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