diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-01-03 16:44:07 -0500 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-01-03 16:47:13 -0500 |
commit | 530e5ff910bf033aa29bba722662457fc69d3d63 (patch) | |
tree | cc533c17987f1d15ebf8fd472f7fa747ca6fe073 /actionview/test | |
parent | f8e040957be9a3835782313c57d25d1e2d86e8dc (diff) | |
download | rails-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/test')
-rw-r--r-- | actionview/test/lib/controller/fake_models.rb | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/actionview/test/lib/controller/fake_models.rb b/actionview/test/lib/controller/fake_models.rb index 80649db88b..ddc915895d 100644 --- a/actionview/test/lib/controller/fake_models.rb +++ b/actionview/test/lib/controller/fake_models.rb @@ -80,7 +80,7 @@ class Comment def to_key; id ? [id] : nil end def save; @id = 1; @post_id = 1 end def persisted?; @id.present? end - def to_param; @id.to_s; end + def to_param; @id && @id.to_s; end def name @id.nil? ? "new #{self.class.name.downcase}" : "#{self.class.name.downcase} ##{@id}" end @@ -101,7 +101,7 @@ class Tag def to_key; id ? [id] : nil end def save; @id = 1; @post_id = 1 end def persisted?; @id.present? end - def to_param; @id; end + def to_param; @id && @id.to_s; end def value @id.nil? ? "new #{self.class.name.downcase}" : "#{self.class.name.downcase} ##{@id}" end @@ -120,7 +120,7 @@ class CommentRelevance def to_key; id ? [id] : nil end def save; @id = 1; @comment_id = 1 end def persisted?; @id.present? end - def to_param; @id; end + def to_param; @id && @id.to_s; end def value @id.nil? ? "new #{self.class.name.downcase}" : "#{self.class.name.downcase} ##{@id}" end @@ -136,7 +136,7 @@ class TagRelevance def to_key; id ? [id] : nil end def save; @id = 1; @tag_id = 1 end def persisted?; @id.present? end - def to_param; @id; end + def to_param; @id && @id.to_s; end def value @id.nil? ? "new #{self.class.name.downcase}" : "#{self.class.name.downcase} ##{@id}" end |