From 73bfb510119e7552378949d635164010e3d5abe2 Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Sat, 12 Apr 2014 12:46:04 +0530 Subject: Change links to 37signals and svn blog to point to new destinations. [ci skip] --- actionview/lib/action_view/helpers/cache_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/cache_helper.rb b/actionview/lib/action_view/helpers/cache_helper.rb index d1c268ec40..4db8930a26 100644 --- a/actionview/lib/action_view/helpers/cache_helper.rb +++ b/actionview/lib/action_view/helpers/cache_helper.rb @@ -11,7 +11,7 @@ module ActionView # The best way to use this is by doing key-based cache expiration # on top of a cache store like Memcached that'll automatically # kick out old entries. For more on key-based expiration, see: - # http://37signals.com/svn/posts/3113-how-key-based-cache-expiration-works + # http://signalvnoise.com/posts/3113-how-key-based-cache-expiration-works # # When using this method, you list the cache dependency as the name of the cache, like so: # -- cgit v1.2.3 From dfac1b188e98d59bda0fac1148c417a9761f7b54 Mon Sep 17 00:00:00 2001 From: Mauro George Date: Sat, 12 Apr 2014 15:14:35 -0300 Subject: CollectionHelpers now accepts a readonly option --- .../action_view/helpers/tags/collection_helpers.rb | 2 +- .../test/template/form_collections_helper_test.rb | 44 ++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/tags/collection_helpers.rb b/actionview/lib/action_view/helpers/tags/collection_helpers.rb index 991f32cea2..8050638363 100644 --- a/actionview/lib/action_view/helpers/tags/collection_helpers.rb +++ b/actionview/lib/action_view/helpers/tags/collection_helpers.rb @@ -44,7 +44,7 @@ module ActionView def default_html_options_for_collection(item, value) #:nodoc: html_options = @html_options.dup - [:checked, :selected, :disabled].each do |option| + [:checked, :selected, :disabled, :readonly].each do |option| current_value = @options[option] next if current_value.nil? diff --git a/actionview/test/template/form_collections_helper_test.rb b/actionview/test/template/form_collections_helper_test.rb index 73fa3b6b4e..8107529149 100644 --- a/actionview/test/template/form_collections_helper_test.rb +++ b/actionview/test/template/form_collections_helper_test.rb @@ -68,6 +68,23 @@ class FormCollectionsHelperTest < ActionView::TestCase assert_no_select 'input[type=radio][value=false][disabled=disabled]' end + test 'collection radio accepts multiple readonly items' do + collection = [[1, true], [0, false], [2, 'other']] + with_collection_radio_buttons :user, :active, collection, :last, :first, :readonly => [true, false] + + assert_select 'input[type=radio][value=true][readonly=readonly]' + assert_select 'input[type=radio][value=false][readonly=readonly]' + assert_no_select 'input[type=radio][value=other][readonly=readonly]' + end + + test 'collection radio accepts single readonly item' do + collection = [[1, true], [0, false]] + with_collection_radio_buttons :user, :active, collection, :last, :first, :readonly => true + + assert_select 'input[type=radio][value=true][readonly=readonly]' + assert_no_select 'input[type=radio][value=false][readonly=readonly]' + end + test 'collection radio accepts html options as input' do collection = [[1, true], [0, false]] with_collection_radio_buttons :user, :active, collection, :last, :first, {}, :class => 'special-radio' @@ -325,6 +342,33 @@ class FormCollectionsHelperTest < ActionView::TestCase assert_no_select 'input[type=checkbox][value=2][disabled=disabled]' end + test 'collection check boxes accepts multiple readonly items' do + collection = (1..3).map{|i| [i, "Category #{i}"] } + with_collection_check_boxes :user, :category_ids, collection, :first, :last, :readonly => [1, 3] + + assert_select 'input[type=checkbox][value=1][readonly=readonly]' + assert_select 'input[type=checkbox][value=3][readonly=readonly]' + assert_no_select 'input[type=checkbox][value=2][readonly=readonly]' + end + + test 'collection check boxes accepts single readonly item' do + collection = (1..3).map{|i| [i, "Category #{i}"] } + with_collection_check_boxes :user, :category_ids, collection, :first, :last, :readonly => 1 + + assert_select 'input[type=checkbox][value=1][readonly=readonly]' + assert_no_select 'input[type=checkbox][value=3][readonly=readonly]' + assert_no_select 'input[type=checkbox][value=2][readonly=readonly]' + end + + test 'collection check boxes accepts a proc to readonly items' do + collection = (1..3).map{|i| [i, "Category #{i}"] } + with_collection_check_boxes :user, :category_ids, collection, :first, :last, :readonly => proc { |i| i.first == 1 } + + assert_select 'input[type=checkbox][value=1][readonly=readonly]' + assert_no_select 'input[type=checkbox][value=3][readonly=readonly]' + assert_no_select 'input[type=checkbox][value=2][readonly=readonly]' + end + test 'collection check boxes accepts html options' do collection = [[1, 'Category 1'], [2, 'Category 2']] with_collection_check_boxes :user, :category_ids, collection, :first, :last, {}, :class => 'check' -- cgit v1.2.3 From 2ddbe87e7acc324ce7e0a4784c4d10b79cc49a40 Mon Sep 17 00:00:00 2001 From: Marcel Morgan Date: Sat, 12 Apr 2014 08:31:00 -0500 Subject: Update documentation to use Rails.application instead References to ``AppName::Application` removed in favour of ``Rails.application`` as generated with a new rails 4.1 app. [ci skip] --- actionview/lib/action_view/helpers/atom_feed_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/atom_feed_helper.rb b/actionview/lib/action_view/helpers/atom_feed_helper.rb index af70a4242a..227ad4cdfa 100644 --- a/actionview/lib/action_view/helpers/atom_feed_helper.rb +++ b/actionview/lib/action_view/helpers/atom_feed_helper.rb @@ -10,7 +10,7 @@ module ActionView # Full usage example: # # config/routes.rb: - # Basecamp::Application.routes.draw do + # Rails.application.routes.draw do # resources :posts # root to: "posts#index" # end -- cgit v1.2.3 From 3964bbc490bdd858b431862bdefa58f477cb2028 Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Sun, 13 Apr 2014 21:58:42 +0300 Subject: `collection_check_boxes` respects `:index` option for the hidden filed name. closes #14147 --- actionview/CHANGELOG.md | 6 ++++++ .../action_view/helpers/tags/collection_check_boxes.rb | 17 +++++++++++++---- .../test/template/form_collections_helper_test.rb | 7 +++++++ 3 files changed, 26 insertions(+), 4 deletions(-) (limited to 'actionview') diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index 8c6db33be7..0302077e1c 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -1,3 +1,9 @@ +* `collection_check_boxes` respects `:index` option for the hidden filed name. + + Fixes #14147. + + *Vasiliy Ermolovich* + * `date_select` helper with option `with_css_classes: true` does not overwrite other classes. *Izumi Wong-Horiuchi* diff --git a/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb b/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb index 8b28e4fc33..6242a2a085 100644 --- a/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb +++ b/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb @@ -28,10 +28,7 @@ module ActionView # Append a hidden field to make sure something will be sent back to the # server if all check boxes are unchecked. if @options.fetch(:include_hidden, true) - hidden_name = @html_options[:name] || "#{tag_name}[]" - hidden = @template_object.hidden_field_tag(hidden_name, "", :id => nil) - - rendered_collection + hidden + rendered_collection + hidden_field else rendered_collection end @@ -42,6 +39,18 @@ module ActionView def render_component(builder) builder.check_box + builder.label end + + def hidden_field + hidden_name = @html_options[:name] + + hidden_name ||= if @options.has_key?(:index) + "#{tag_name_with_index(@options[:index])}[]" + else + "#{tag_name}[]" + end + + @template_object.hidden_field_tag(hidden_name, "", id: nil) + end end end end diff --git a/actionview/test/template/form_collections_helper_test.rb b/actionview/test/template/form_collections_helper_test.rb index 8107529149..5e991d87ad 100644 --- a/actionview/test/template/form_collections_helper_test.rb +++ b/actionview/test/template/form_collections_helper_test.rb @@ -221,6 +221,13 @@ class FormCollectionsHelperTest < ActionView::TestCase assert_select "input[type=hidden][name='user[other_category_ids][]'][value=]", :count => 1 end + test 'collection check boxes generates a hidden field with index if it was provided' do + collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')] + with_collection_check_boxes :user, :category_ids, collection, :id, :name, { index: 322 } + + assert_select "input[type=hidden][name='user[322][category_ids][]'][value=]", count: 1 + end + test 'collection check boxes does not generate a hidden field if include_hidden option is false' do collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')] with_collection_check_boxes :user, :category_ids, collection, :id, :name, include_hidden: false -- cgit v1.2.3 From 38426458d682ceca7b00c9794f5680767e1a2d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Mon, 14 Apr 2014 11:53:47 -0300 Subject: Use the index on hidden field --- actionview/test/template/form_helper_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionview') diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb index b5e9801776..155801dd02 100644 --- a/actionview/test/template/form_helper_test.rb +++ b/actionview/test/template/form_helper_test.rb @@ -1420,7 +1420,7 @@ class FormHelperTest < ActionView::TestCase expected = whole_form("/posts", "new_post", "new_post") do "" + "" + - "" + "" end assert_dom_equal expected, output_buffer -- cgit v1.2.3