开发者

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' => 'us开发者_如何学JAVAers#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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜