diff options
author | Zachary Scott <e@zzak.io> | 2015-06-14 09:24:42 -0400 |
---|---|---|
committer | Zachary Scott <e@zzak.io> | 2015-06-14 09:24:42 -0400 |
commit | 88cd09fa47ddf9ea952b2c4d117d725b0d537bae (patch) | |
tree | 00c6378bd98c3388f7e45aa4c7c89e50f97fd4d7 /actionview/lib/action_view/helpers | |
parent | 361014a8f54cd55a829a1aff74052b450a1b442e (diff) | |
parent | 58a75ffbfe7ee622a4a8551b2bfbbe01b396135e (diff) | |
download | rails-88cd09fa47ddf9ea952b2c4d117d725b0d537bae.tar.gz rails-88cd09fa47ddf9ea952b2c4d117d725b0d537bae.tar.bz2 rails-88cd09fa47ddf9ea952b2c4d117d725b0d537bae.zip |
Merge pull request #20548 from maurogeorge/collection_check_boxes-rdoc-gotcha
Add gotcha to RDoc of collection_check_boxes
Diffstat (limited to 'actionview/lib/action_view/helpers')
-rw-r--r-- | actionview/lib/action_view/helpers/form_options_helper.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/actionview/lib/action_view/helpers/form_options_helper.rb b/actionview/lib/action_view/helpers/form_options_helper.rb index d3deee0df3..1b7b188d65 100644 --- a/actionview/lib/action_view/helpers/form_options_helper.rb +++ b/actionview/lib/action_view/helpers/form_options_helper.rb @@ -707,6 +707,27 @@ module ActionView # collection_check_boxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b| # b.label(:"data-value" => b.value) { b.check_box + b.text } # end + # + # ==== Gotcha + # + # When no selection is made for a collection of checkboxes most + # web browsers will not send any value. + # + # For example, if we have a +User+ model with +category_ids+ field and we + # have the following code in our update action: + # + # @user.update(params[:user]) + # + # If no +category_ids+ are selected then we can safely assume this field + # will not be updated. + # + # This is possible thanks to a hidden field generated by the helper method + # for every collection of checkboxes. + # This hidden field is given the same field name as the checkboxes with a + # blank value. + # + # In the rare case you don't want this hidden field, you can pass the + # <tt>include_hidden: false</tt> option to the helper method. def collection_check_boxes(object, method, collection, value_method, text_method, options = {}, html_options = {}, &block) Tags::CollectionCheckBoxes.new(object, method, self, collection, value_method, text_method, options, html_options).render(&block) end |