1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[undefined method `for' for・・・]deviseのストロングパラメーターが編集出来ないエラー。

Posted at

概要

gem deviseにおいて、configure_permitted_parametersメソッドを作る。その中ではdevise_parameter_sanitizerメソッドを使いストロングパラメーターを編集する。この見慣れた光景でエラーが起きる。**undefined method `for' for・・・**というエラー。調べてみるとバージョン4.1.0以降からdeviseの仕様が変わったらしい。
スクリーンショット 2016-07-10 11.28.18.png

解決方法

gem deviseのgithubのStrong Parametersを見ましょう。そうすると、下記のような記述にしろと言われてる。

application_controller.rb
class ApplicationController < ActionController::Base
  before_action :configure_permitted_parameters, if: :devise_controller?

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:sign_up, keys: [:username])
  end
end

つまり、
僕の記述の場合は、これから

devise_parameter_sanitizer.for(:account_update).push(:firstname, :secondname, :nickname, :introduction, :job, :age, :avatar, :local)

こうしろということですね。

devise_parameter_sanitizer.permit(:account_update, keys: [:firstname, :secondname, :nickname, :introduction, :job, :age, :avatar, :local])

はい、無事動きました。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?