Skip to content

Commit

Permalink
Merge pull request #16402 from bogdan/select_with_empty_block
Browse files Browse the repository at this point in the history
Fixed #select form builder helper to support block without html output
  • Loading branch information
spastorino committed Aug 6, 2014
2 parents a819211 + 7a0c2ba commit d5be083
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionview/lib/action_view/helpers/tags/select.rb
Expand Up @@ -3,7 +3,7 @@ module Helpers
module Tags # :nodoc:
class Select < Base # :nodoc:
def initialize(object_name, method_name, template_object, choices, options, html_options)
@choices = block_given? ? template_object.capture { yield } : choices
@choices = block_given? ? template_object.capture { yield || "" } : choices
@choices = @choices.to_a if @choices.is_a?(Range)

@html_options = html_options
Expand Down
13 changes: 13 additions & 0 deletions actionview/test/template/form_options_helper_test.rb
Expand Up @@ -591,6 +591,19 @@ def test_select_under_fields_for_with_block
)
end

def test_select_under_fields_for_with_block_without_options
@post = Post.new

output_buffer = fields_for :post, @post do |f|
concat(f.select(:category) {})
end

assert_dom_equal(
"<select id=\"post_category\" name=\"post[category]\"></select>",
output_buffer
)
end

def test_select_with_multiple_to_add_hidden_input
output_buffer = select(:post, :category, "", {}, :multiple => true)
assert_dom_equal(
Expand Down

0 comments on commit d5be083

Please sign in to comment.