0
我很難嘗試追查錯誤。我使用單獨的更新方法在用戶登錄時更改我的用戶密碼。我已經發布了下面的代碼。嘗試在軌道上使用ruby中的替代更新方法時出錯
在users_controller:
def change_password
@user = current_user
@user_password_matches = User.authenticate(current_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, 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'
錯誤:
SyntaxError in Users#account
Showing /Users/greg/site/app/views/users/account.html.erb where line #27 raised:
/Users/greg/site/app/views/users/account.html.erb:27: syntax error, unexpected keyword_do_block, expecting tASSOC
...> true, change_password_path do |f| @output_buffer.safe_conc...
... ^
/Users/greg/site/app/views/users/account.html.erb:51: syntax error, unexpected keyword_ensure, expecting $end
Extracted source (around line #27):
24: </div>
25: <h3><a href="#">Change Password</a></h3>
26: <div>
27: <p> <%= form_for @user, :remote => true, change_password_path do |f| %>
28: Current password: <%= password_field_tag :current_password, :placeholder => "Password" %><br />
29: New password: <%= f.password_field :password, :placeholder => "Password" %><br />
30: Confirm password: <%= f.password_field :password_confirmation, :placeholder => "Confirm Password" %><br />
我確定問題來自於我的表單和路線,任何人都可以通過解決方案幫助我做到這一點?
親切的問候
這解決了第一個問題,現在我越來越:路由錯誤 沒有路由匹配{:controller =>「users」,:action =>「change_password」,:format =>#<用戶id:1,email:「[email protected]」,encrypted_password:「$ 2a $ 10 $ lgmrRTYFUUr WStLl1Y.Oo.LqQ2Ybxa29YkDFw61/KG9O ...「,password_salt:」$ 2a $ 10 $ lgmrRTYFUUrWStLl1Y.Oo。「,用戶名:」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「>} – LondonGuy 2012-01-13 11:50:57
你的'UsersController'中有'change_password'方法嗎?如果你這樣做,那麼它是否在你的'routes.rb'中啓用? – 2012-01-13 11:52:18
是的,它顯示在上面的代碼中。 – LondonGuy 2012-01-13 11:53:40