aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorTravis Grathwell <tjgrathwell@gmail.com>2014-12-29 18:12:03 -0800
committerEugenia Dellapenna <eugenia.dellapenna@gmail.com>2014-12-29 18:12:03 -0800
commit3efd90ac5b15d376bc5780d08d6e07d5a2b50ff1 (patch)
treea33525691bcc0fb0a3650c2953352f7da73ff903 /actionpack
parent241ccaef88e494657ff4121ef31d73160237fd6c (diff)
downloadrails-3efd90ac5b15d376bc5780d08d6e07d5a2b50ff1.tar.gz
rails-3efd90ac5b15d376bc5780d08d6e07d5a2b50ff1.tar.bz2
rails-3efd90ac5b15d376bc5780d08d6e07d5a2b50ff1.zip
Fix form_for to work with objects that implement to_model
Previously, if you tried to use form_for with a presenter object that implements to_model, it would crash in action_dispatch/routing/polymorphic_routes.rb when asking the presenter whether it is .persisted? Now, we always ask .persisted? of the to_model object instead. This seems to been an issue since 1606fc9d840da869a60213bc889da6fcf1fdc431 Signed-off-by: Eugenia Dellapenna <eugenia.dellapenna@gmail.com>
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/routing/polymorphic_routes.rb11
1 files changed, 6 insertions, 5 deletions
diff --git a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
index d9bd277d62..2e116ea9cd 100644
--- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
+++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
@@ -247,7 +247,7 @@ module ActionDispatch
args = []
model = record.to_model
- name = if record.persisted?
+ name = if model.persisted?
args << model
model.model_name.singular_route_key
else
@@ -290,11 +290,12 @@ module ActionDispatch
when Class
@key_strategy.call record.model_name
else
- if record.persisted?
- args << record.to_model
- record.to_model.model_name.singular_route_key
+ model = record.to_model
+ if model.persisted?
+ args << model
+ model.model_name.singular_route_key
else
- @key_strategy.call record.to_model.model_name
+ @key_strategy.call model.model_name
end
end