3.1.3
我试图指出我改换的正确途径——我的用户——控制器的密码方法。
I m 目前正出现这一错误:
Routing Error
No route matches {:action=>"change_password", :controller=>"users", :format=>#<User id: 1, email: "[email protected]", encrypted_password: "$2a$10$lgmrRTYFUUrWStLl1Y.Oo.LqQ2Ybxa29YkDFw61/KG9O...", password_salt: "$2a$10$lgmrRTYFUUrWStLl1Y.Oo.", username: "foobar", created_at: "2012-01-07 23:02:29", updated_at: "2012-01-13 11:16:45", password_reset_token: nil, password_reset_sent_at: "2012-01-08 12:23:30">}
用户——控制器:
def change_password
@user = current_user
@user_password_matches = User.authenticate(@user.email, params[:current_password])
if @user_password_matches.update_attributes(params[:user])
login @user
format.js { render :js => "window.location = #{settings_account_path} " }
flash[:success] = "Password updated"
else
format.js { render :form_errors }
end
end
认为:
<%= form_for @user, :remote => true, :url => change_password_path(@user) do |f| %>
Current password: <%= password_field_tag :current_password, :placeholder => "Password" %><br />
New password: <%= f.password_field :password, :placeholder => "Password" %><br />
Confirm password: <%= f.password_field :password_confirmation, :placeholder => "Confirm Password" %><br />
<%= f.submit update %>
路线:
resources :users do
member do
put :change_password
end
end
resources :users
resources :sessions
resources :passwords
resources :profiles
root :to => "users#new"
match success => "users#success"
match login => "sessions#new"
match logout => "sessions#destroy"
match reset_password => "passwords#new"
match setup_new_password => "passwords#edit"
match settings , :to => "users#settings"
match "/settings/account", :to => "users#account"
match "/settings/edit_profile", :to => "profiles#edit_profile"
match /:username , :controller => users , :action => show
所有希望做的Im只有用户进入密码(现时为密码)才能成功地通过认证(我使用的相同方法在用户中记录密码,确认密码与存储在db中的密码相匹配),如果确实使用用户的密码,则更新db中的属性。
幼儿园