开发者

No action respond to id in rails routing problem

I am adding a functionality of resetting password in my rails application

In my users page , i have all the users listing

If i am logging in as a admin below the users a link to reset password to users are available which will set a default password to them

  <%= link_to "Reset Password开发者_如何学JAVA",reset_password_user_path  %>

In my controller users

    def reset_password

     @user = params[:user]
     puts "which user #{@user}"
     @user.password = "12345"
  if @user.save
    flash[:notice] = "Password successfully reseted"
    redirect_to user_path
  else
    flash[:error]= "Password not reste!"
    redirect_to user_path
  end

  end

In my routes

   map.resources :users, :member => {:reset_password => :post}

When i run my users page , i am getting the error as below

  reset_password_user_url failed to generate from {:action=>"reset_password", :controller=>"users"} - you may have ambiguous routes, or you may need to supply additional parameters for this route.  content_url has the following required parameters: ["users", :id, "reset_password"] - are they all satisfied?

WHen i gave the link as

   <%= link_to "Reset Password",reset_password_user_path(user)  %>

then i am getting the error as No action respond to 2

  Processing UsersController#2 (for 127.0.0.1 at 2011-03-14 11:38:33) [GET]
   Parameters: {"action"=>"2", "id"=>"reset_password", "controller"=>"users"}

How to resolve this..


Alternatively <%= link_to "Reset Password", reset_password_user_path(user), :method => "post" %> assuming you have Prototype or jQuery.

This way you are still posting to the action as it makes changes to the user.


Try with get method instead of post in routes.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜