1

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

  • I'm using Rails 3.0.4
  • I've tried taking out every other route except for the ones that I've mentioned here, and I still can't figure out why it's not working.
Groovetrain
  • 3,315
  • 19
  • 23
  • hi, I just tested your code and it works fine... did you check that the method on the form is really post? did you try to restart your server to load the new routes? And remember there mustn't be any reset code in the form's action URL. – sled Mar 05 '11 at 13:57
  • The start tag of the form that is generated is:
    – Groovetrain Mar 05 '11 at 14:22
  • If it works fine for you then there must be something else going on in my routes. At least it works for _somebody_ :) – Groovetrain Mar 05 '11 at 14:24

1 Answers1

6

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.

Groovetrain
  • 3,315
  • 19
  • 23
  • 2
    Same thing happened to me. Instead of changing verb from 'post' to 'put' i changed form_for from 'form_for @user' to 'form_for :user' – sha1dy Mar 30 '11 at 12:24