0
0

More than 3 years have passed since last update.

Rails Devise+carrierwaveでのストロングパラメーター メモ

Last updated at Posted at 2019-11-20

こんにちは@yukifreeworld12です。

自分用メモ
ストロングパラメーターのkeysが間違っていて画像が保存されず書き方を調べてうまくいったのでメモ。

Deviseを使っている場合の画像用のストロングパラメーター。

モデル作成+アップローダー作成後にストロングパラメーターを追加
                ↓
keysはregistration.htmlなどのフォームを見ればわかるのでそれを全部追加
                ↓
アップローダーの紐付け

app/models/user.rb
mount_uploader :avatar, AvatarUploader

今回の場合↓

registration_controller.rb
protected

  def configure_account_signup_params
    devise_parameter_sanitizer.permit(:sign_up, keys: [:username, :image, :email, :password, :password_confirmation])
  end

  def configure_account_update_params
    devise_parameter_sanitizer.permit(:account_update, keys: [:username, :image, :image_cache, :remove_image, :email, :password, :password_confirmation, :current_password])
  end
  # The path used after sign up for inactive accounts.
  # def after_inactive_sign_up_path_for(resource)
  #   super(resource)
  # end
end

参考サイト

最後に

今日も見てくれてホンマありがとな!!
記事がええなと思ったらフォローといいねホンマよろしくな!!
(ジョーブログ風に)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0