Reputation: 2723
I'm playing with a test rails app. However I stumbled on a problem I can't resolve. I've a users controller and in it there's an activate method.
In the routes.rb file I have
match 'activate/:email/:validation_code' => 'users#activate', :as => :activate_user, :via => :get
After that I try to use activate_user_path(@user)
but a routing error is raised.
No route matches {:controller=>"users", :action=>"activate", :email=>#<User id: 12, email: "[email protected]", validation_code: "zbBPLQUsBgPvEJfcjxmXuxFxuJAKEoqQNASkbybihpnmzSbhxdC...", active: false, created_at: "2011-11-10 14:56:23", updated_at: "2011-11-10 14:56:23">}
Running rake routes
shows the routing is there:
activate_user GET /activate/:email/:validation_code(.:format) {:controller=>"users", :action=>"activate"}
I tried searching for this problem, but usually this happens when you forget to pass the object that's needed to build the route.
All help is appreciated :)
Upvotes: 1
Views: 1432
Reputation: 7824
Does activate_user_path(:email => @user.email, :validataion_code => @user.validation_code) works for you?
EDIT
I don't know why, but when I've changed: validation_code to code it works.
match 'activate/:email/:code' => 'users#activate', :as => :activate_user, :via => :get
Probably in rails you can't use var names in routes with underscore, but this has to be verified.
Upvotes: 0
Reputation: 11
I would make sure you are actually invoking a GET and not a POST as the method.
If you are submitting a form, it defaults to POST, which would mean you don't have a matching route, the route you listed above only works for GET requests.
Upvotes: 1