diff options
author | Mauro George <maurogot@gmail.com> | 2015-01-02 16:53:38 -0200 |
---|---|---|
committer | Mauro George <maurogot@gmail.com> | 2015-09-24 19:58:15 -0300 |
commit | 491013e06d0ad4a296cc23be6c4a48bb0a98106f (patch) | |
tree | 8b4f0d654f61d02c16770b031c6672fb7bbc1bc5 /actionview/lib/action_view/helpers/tags/collection_helpers.rb | |
parent | bff28bab29d4a3b950f75493fc1b1ed99d63426b (diff) | |
download | rails-491013e06d0ad4a296cc23be6c4a48bb0a98106f.tar.gz rails-491013e06d0ad4a296cc23be6c4a48bb0a98106f.tar.bz2 rails-491013e06d0ad4a296cc23be6c4a48bb0a98106f.zip |
Add a hidden field on the collection_radio_buttons
This will avoid a error be raised when the only input on the form is the
`collection_radio_buttons`.
Diffstat (limited to 'actionview/lib/action_view/helpers/tags/collection_helpers.rb')
-rw-r--r-- | actionview/lib/action_view/helpers/tags/collection_helpers.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/actionview/lib/action_view/helpers/tags/collection_helpers.rb b/actionview/lib/action_view/helpers/tags/collection_helpers.rb index 8050638363..fea4c8d4ec 100644 --- a/actionview/lib/action_view/helpers/tags/collection_helpers.rb +++ b/actionview/lib/action_view/helpers/tags/collection_helpers.rb @@ -79,6 +79,32 @@ module ActionView yield item, value, text, default_html_options.merge(additional_html_options) end.join.html_safe end + + def render_collection_for(builder_class, &block) #:nodoc: + options = @options.stringify_keys + rendered_collection = render_collection do |item, value, text, default_html_options| + builder = instantiate_builder(builder_class, item, value, text, default_html_options) + + if block_given? + @template_object.capture(builder, &block) + else + render_component(builder) + end + end + + # Append a hidden field to make sure something will be sent back to the + # server if all radio buttons are unchecked. + if options.fetch('include_hidden', true) + rendered_collection + hidden_field + else + rendered_collection + end + end + + def hidden_field #:nodoc: + hidden_name = @html_options[:name] || "#{tag_name(false, @options[:index])}[]" + @template_object.hidden_field_tag(hidden_name, "", id: nil) + end end end end |