I am about to migrate my rails 3 application to rails 4.

There are some additional routes on my ressources that make some problems. I get an error message for this lines in my route file:

resources :teams do
...   
   get 'apply' => 'teams#apply_membership', as: :apply_membership
   post 'apply' => 'teams#apply_membership_save', as: :apply_membership
...

This is the generated error message

You may have defined two routes with the same name using the `:as` option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created with `resources` as explained here: 
http://guides.rubyonrails.org/routing.html#restricting-the-routes-created

In rails3 it was possible to define a get and a post route using the same alias and routing them to different controler methods.

Can I do this in rails4, too? And if yes, how does it have to look like in my route file?

有帮助吗?

解决方案

You can not take two route name with same name. but you have done it. so please change,

get 'apply' => 'teams#apply_membership', as: :apply_membership
post 'apply' => 'teams#apply_membership_save', as: :update_membership

Take a look here for rails routings. http://guides.rubyonrails.org/routing.html

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top