Take the 2-minute tour ×

After solving the other problem with routes , now I have another one.

I have this route in my routes.rb:

match "user/create_new_password/:reset_password_key" =>"users#create_new_password", :via=>[:post, :get], :as=>:create_new_password

I can test it in my functional tests like this:

test "should create new password " do
    post :create_new_password, {:user=>{:password=>"123456", :password_confirmation=>"123456"}, :reset_password_key=>user.reset_password_key}

In my view, I have the following form:

=simple_form_for @user, :url=>create_new_password_path do |f|
    =f.input :password, :label=>I18n.t("activerecord.attributes.user.email")
    =f.input :password_confirmation, :label=>I18n.t("activerecord.attributes.user.password_confirmation")
    =f.submit I18n.t "activerecord.actions.user.create_new_password"

When I submit the form, I get:

No route matches "/user/create_new_password/OqQxYTgjYKxXgvbAsTsWtMnIpMOpsjCRzLGZmJZLSbYtjvcvdpO"

The big string, is the reset_password_key.

I have tested it in functional tests with the same value for reset_password_key.

The relevant output for rake routes is:

create_new_password POST|GET /user/create_new_password/:reset_password_key(.:format) {:controller=>"users", :action=>"create_new_password"}

I'm missing something...

share|improve this question
Have to ask: have you started the server since editing the routes? If so, can you post the contents of your config/routes.rb file? Thanks and good luck! –  Brandon Tilley Feb 10 '11 at 0:06
Yes, many times. However I've found the problem. I'm learning it the hard way. I underestimated the cleverness of Rails... Since I'm editing a existing entity, this case a @user, rails is setting the _method to :put.... so, I haven't any put in my route... –  Joao Pereira Feb 10 '11 at 0:32
add comment

1 Answer

up vote 1 down vote accepted

As answered to BinaryMuse's comment, I've found what went wrong... I checked the request in firebug and found that a _method=put was being sent with the POST. Rails cleverness detected that I'm editing and existing instance of User (@user), so it defaults the POTS to a PUT, using the param _method.

The problem is that in my routes I haven't the method PUT in the :via array. Just changed to:

 match "user/create_new_password/:reset_password_key" =>"users#create_new_password",:via=>[:get, :put], :as=>:create_new_password

And in the controller:

def create_new_password
   if request.put?
      #change password
     #render template


share|improve this answer
add comment

Your Answer


