ruby-on-rails-3routesnamed-routing

Rails 3 Routes: Named routes. "No route matches"


So I'm getting a 'No route matches' error, and being new to Rails 3 (and Rails in general), I really don't know what the problem is. Here are the pertinent routes:

resources :users
#...
match 'reset_password(/:reset_password_code)' => 'users#reset_password', :as => :reset_password, :via => :get
match 'reset_password' => 'users#reset_password_submit', :as => :reset_password, :via => :post

The GET method works fine. I get a routing error when the form POSTs that's generated on the get page, which starts like this.

<%= form_for @user, :url => reset_password_url do |f| %>

It looks like it's posting to the right spot, as the url is generated using 'reset_password_url', it's posting to it, and the url looks as it should... anyone have any ideas?

UPDATE


Solution

  • Figured it out!

    In my form, rails was (correctly) assuming that since I had a user that I was using with the form_for helper, that I wanted to update the user, not make a new one.

    Therefore, it was using the PUT method to post my form. To solve the routing problem, I just had to change the last route to:

    match 'reset_password' => 'users#reset_password_submit', :as => :reset_password, :via => :put
    

    I only found the issue after using the Web Inspector in webkit to see the whole request, and looked at the _method parameter being sent in.