2013-09-01 78 views
0

在Rails 3中它工作得很好,但用我的新Rails4 Appp我不知道最新的問題。允許用戶在未提供密碼的情況下編輯其帳戶| Rails4

該指南對Devise GitHub Page

註冊記憶控制器

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

enter image description here

回答

1

我還不知道這是一個很好的做法,但我在RegistrationsController更新操作改爲

@user.update_attributes(account_update_params) 
相關問題