10000 Form builder patch by qoobaa · Pull Request #1760 · activeadmin/activeadmin · GitHub
[go: up one dir, main page]

Skip to content

Form builder patch #1760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/active_admin/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ def initialize(*args)
def inputs(*args, &block)
# Store that we are creating inputs without a block
@inputs_with_block = block_given? ? true : false
content = with_new_form_buffer { super }
content = with_new_form_buffer do
super
# Ensure the buffer is returned instead of the block result itself
form_buffers.last
end
form_buffers.last << content.html_safe
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rewrite it like this:

def inputs(*args, &block)
  @inputs_with_block = !!block_given? # Record whether a block is passed
  form_buffers.last << with_new_form_buffer{ super; form_buffers.last }.html_safe
end


Expand Down
17 changes: 17 additions & 0 deletions spec/unit/form_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -404,4 +404,21 @@ def build_form(options = {}, form_object = Post.new, &block)
end
end

describe "inputs block with nil return value" do

let :body do
build_form do |f|
f.inputs do
f.input :title
nil
end
end
end

it "should generate a single input field" do
body.should have_tag("input", :attributes => { :type => "text", :name => "post[title]" })
end

end

end
0