aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2017-01-03 16:44:07 -0500
committerRafael Mendonça França <rafaelmfranca@gmail.com>2017-01-03 16:47:13 -0500
commit530e5ff910bf033aa29bba722662457fc69d3d63 (patch)
treecc533c17987f1d15ebf8fd472f7fa747ca6fe073 /actionview/lib/action_view
parentf8e040957be9a3835782313c57d25d1e2d86e8dc (diff)
downloadrails-530e5ff910bf033aa29bba722662457fc69d3d63.tar.gz
rails-530e5ff910bf033aa29bba722662457fc69d3d63.tar.bz2
rails-530e5ff910bf033aa29bba722662457fc69d3d63.zip
Generate indexed names in input even when objects are not persisted
When you ask to generate multiple nested inputs using: field_for('comments[]', Comment.new) do |c| c.text_field :body Rails should generated the names like `post[comments][][body]`. To make sure we don't have regression the fake models now use the same implementation of `#to_param` as `ActiveRecord::Base` Fixes #26942
Diffstat (limited to 'actionview/lib/action_view')
-rw-r--r--actionview/lib/action_view/helpers/tags/base.rb15
1 files changed, 13 insertions, 2 deletions
diff --git a/actionview/lib/action_view/helpers/tags/base.rb b/actionview/lib/action_view/helpers/tags/base.rb
index 74d6324771..0895533a60 100644
--- a/actionview/lib/action_view/helpers/tags/base.rb
+++ b/actionview/lib/action_view/helpers/tags/base.rb
@@ -16,7 +16,14 @@ module ActionView
@skip_default_ids = options.delete(:skip_default_ids)
@allow_method_names_outside_object = options.delete(:allow_method_names_outside_object)
@options = options
- @auto_index = Regexp.last_match ? retrieve_autoindex(Regexp.last_match.pre_match) : nil
+
+ if Regexp.last_match
+ @generate_indexed_names = true
+ @auto_index = retrieve_autoindex(Regexp.last_match.pre_match)
+ else
+ @generate_indexed_names = false
+ @auto_index = nil
+ end
end
# This is what child classes implement.
@@ -167,7 +174,11 @@ module ActionView
end
def name_and_id_index(options)
- options.key?("index") ? options.delete("index") || "" : @auto_index
+ if options.key?("index")
+ options.delete("index") || ""
+ elsif @generate_indexed_names
+ @auto_index || ""
+ end
end
def skip_default_ids?