diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-12-30 11:15:07 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-12-30 11:23:47 -0300 |
commit | 0c070ae568767a2c8e9bdec49ab3a1a24f113382 (patch) | |
tree | 7e019d49da88a74d542c121e44313e62325a8ff7 /actionpack | |
parent | 2b12288139f9bad6cf6d058d93af66cdf598dda9 (diff) | |
parent | 3efd90ac5b15d376bc5780d08d6e07d5a2b50ff1 (diff) | |
download | rails-0c070ae568767a2c8e9bdec49ab3a1a24f113382.tar.gz rails-0c070ae568767a2c8e9bdec49ab3a1a24f113382.tar.bz2 rails-0c070ae568767a2c8e9bdec49ab3a1a24f113382.zip |
Merge pull request #18251 from tjgrathwell/fix-polymorphic-routes-to-model
Fix form_for to work with objects that implement to_model
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG.md | 4 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/routing/polymorphic_routes.rb | 11 |
2 files changed, 10 insertions, 5 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 98b573e21e..839cbc76e7 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,7 @@ +* Fix how polymorphic routes works with objects that implement `to_model`. + + *Travis Grathwell* + * Stop converting empty arrays in `params` to `nil` This behaviour was introduced in response to CVE-2012-2660, CVE-2012-2694 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 |