我知道在Devise wiki页面上,他们会在这里解释如何执行此操作:https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-edit-their-account-without-providing-a-password
但我是Rails(4)的新手,我正在努力做好几个小时,但我一直收到“密码不能是空白消息”。任何人都可以解释如何为rails 4做什么?
更新:这是我的代码,我使用此代码在控制器中创建一个名为Registrations的文件:
class RegistrationsController < Devise::RegistrationsController
def update
# For Rails 4
account_update_params = devise_parameter_sanitizer.sanitize(:account_update)
# For Rails 3
# account_update_params = params[:user]
# required for settings form to submit when password is left blank
if account_update_params[:password].blank?
account_update_params.delete("password")
account_update_params.delete("password_confirmation")
end
@user = User.find(current_user.id)
if @user.update_attributes(account_update_params)
set_flash_message :notice, :updated
# Sign in the user bypassing validation in case their password changed
sign_in @user, :bypass => true
redirect_to after_update_path_for(@user)
else
render "edit"
end
end
end
在我的路线/配置中,我把它放在:
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks", :registrations => "registrations" }
我不明白我还有什么要做的......