2011-03-14 61 views
0

我加入我的Rails應用程序重置密碼無動作在軌路由問題

在我的用戶頁面的功能應對ID,我把所有的用戶列表

如果我作爲一個登錄管理員下面的用戶鏈接重設密碼,用戶可將設置默認密碼給他們

<%= link_to "Reset Password",reset_password_user_path %> 

在我的控制器用戶

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 

在我的路線

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

運行我的用戶頁面上,我得到如下錯誤

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? 

當我發出的環節

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

那麼我得到錯誤爲無動作響應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"} 

如何解決此問題..

回答

2

或者<%= link_to "Reset Password", reset_password_user_path(user), :method => "post" %>假設你有Prototype或jQuery。

這樣您仍然發佈到該操作,因爲它會更改用戶。

0

嘗試使用get方法而不是在路徑中發佈。