我需要在用户编辑页面时调用函数。
这是我的settings_controller.rb:
class SettingsController < ApplicationController
def update
@user = User.find(current_user.id)
email_changed = @user.email != params[:user][:email]
password_changed = !params[:user][:password].empty?
successfully_updated = if email_changed or password_changed
@user.update_with_password(params[:user])
else
@user.update_without_password(params[:user])
end
if successfully_updated
# Sign in the user bypassing validation in case his password changed
sign_in @user, :bypass => true
//need to call action here
else
render "edit"
end
end
端
如果成功更新,我需要重定向用户。
在我的routes.rb中:
devise_for :users, :controllers => {:registrations => 'registrations', :settings => 'settings'}
或者我做错了什么?
答案 0 :(得分:2)
settings
中没有devise_for
路由。
查看RegistrationController
in devise.
您可以覆盖此内容:
class SettingsController < Devise::RegistrationsController
def update
@user = User.find(current_user.id)
email_changed = @user.email != params[:user][:email]
password_changed = !params[:user][:password].empty?
successfully_updated = if email_changed or password_changed
@user.update_with_password(params[:user])
else
@user.update_without_password(params[:user])
end
if successfully_updated
# Sign in the user bypassing validation in case his password changed
sign_in @user, :bypass => true
//need to call action here
else
render "edit"
end
end
end
路由:
devise_for :users, :controllers => {:registrations => 'settings'}