From 57bf92c6de125adc45bb006115d22d07270618b3 Mon Sep 17 00:00:00 2001 From: Bogdan Gusiev Date: Mon, 23 Sep 2013 14:25:42 +0300 Subject: [PATCH] Ability to pass block to AV#select helper Example: = select(report, "campaign_ids") do - available_campaigns.each do |c| %option{:data => {:tags => c.tags.to_json}, :value => c.id}= c.name --- actionview/CHANGELOG.md | 8 ++++++++ .../action_view/helpers/form_options_helper.rb | 8 ++++---- actionview/lib/action_view/helpers/tags/select.rb | 3 ++- .../test/template/form_options_helper_test.rb | 15 +++++++++++++++ 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index 1d91fdfe8d1..56ceae116d5 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -1,3 +1,11 @@ +* Ability to pass block to `select` helper + + = select(report, "campaign_ids") do + - available_campaigns.each do |c| + %option{:data => {:tags => c.tags.to_json}, :value => c.id}= c.name + + *Bogdan Gusiev* + * Handle `:namespace` form option in collection labels *Vasiliy Ermolovich* diff --git a/actionview/lib/action_view/helpers/form_options_helper.rb b/actionview/lib/action_view/helpers/form_options_helper.rb index fcd151ac327..d9ccca8880e 100644 --- a/actionview/lib/action_view/helpers/form_options_helper.rb +++ b/actionview/lib/action_view/helpers/form_options_helper.rb @@ -152,8 +152,8 @@ module ActionView # In case if you don't want the helper to generate this hidden field you can specify # include_hidden: false option. # - def select(object, method, choices, options = {}, html_options = {}) - Tags::Select.new(object, method, self, choices, options, html_options).render + def select(object, method, choices = nil, options = {}, html_options = {}, &block) + Tags::Select.new(object, method, self, choices, options, html_options, &block).render end # Returns ", + output_buffer + ) + end + def test_select_with_multiple_to_add_hidden_input output_buffer = select(:post, :category, "", {}, :multiple => true) assert_dom_equal(