在Rails 3中它运行得很好,但是使用我的新Rails4 Appp我不知道这个问题是什么。
上的指南我的注册控制器
def update
# required for settings form to submit when password is left blank
if params[:user][:password].blank?
params[:user].delete("password")
params[:user].delete("password_confirmation")
end
@user = User.find(current_user.id)
if @user.update_without_password(devise_parameter_sanitizer.sanitize(:account_update))
set_flash_message :notice, :updated
# Sign in the user bypassing validation in case his password changed
sign_in @user, :bypass => true
redirect_to after_update_path_for(@user)
else
render "edit"
end
end
我的应用程序控制器
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) do |u|
u.permit(:name, :first_name, :user_name, :email, :password, :password_confirmation, :provider, :uid)
end
devise_parameter_sanitizer.for(:account_update) do |u|
u.permit(:name, :email, :password, :password_confirmation, :first_name, :last_name,
:user_name, :avatar, :profile_cover, :facebook_link,
:twitter_link, :instagram_link, :status)
end
end
我将控制器添加到路线
:registrations => "registrations"
我使用下面的相应方法更改了更新调用:
@user.update_without_password(devise_parameter_sanitizer.sanitize(:account_update))
但我收到NoMethodError in RegistrationsController#update
错误。
答案 0 :(得分:1)
我还不知道这是不是很好的做法,但我在RegistrationsController
更新了更改操作
@user.update_attributes(account_update_params)