deviseを用いてログイン、新規登録機能を実装しましたが、
既存で作成していたユーザー編集機能で「Password can't be blank」というパスワードエラーが発生するようになりました。
対処するため他の方がやっていたパスワードを求めない処理を真似て改修していましたが、うまくいきません。
コントローラーが結びついていなくて適用されてないからだと
思いますが、解決策はありますでしょうか?
routes.rbの部分は本来
devise_for :users, controllers: {
registrations: "users/registrations"
}
でしたが変わらずの状態で、
また適用したいのはusers/:id/updateの部分なので
変更しましたがうまくいきませんでした。
ご教授宜しくお願いします。
routes.rb
1devise_for :users, controllers: { 2 registrations: "users/update" 3 }
registrations_controller.rb
1class Users::RegistrationsController < Devise::RegistrationsController 2 # before_action :configure_sign_up_params, only: [:create] 3 # before_action :configure_account_update_params, only: [:update] 4 5 protected 6 def update_resource(resource, params) 7 resource.update_without_current_password(params) 8 end 9end
user.rb
1def update_without_current_password(params, *options) 2 params.delete(:current_password) 3 4 if params[:password].blank? && params[:password_confirmation].blank? 5 params.delete(:password) 6 params.delete(:password_confirmation) 7 end 8 9 result = update_attributes(params, *options) 10 clean_up_passwords 11 result 12 end 13end
あなたの回答
tips
プレビュー