NameError (undefined local variable or method `dev

2019-04-18 03:14发布

I'm using devise for user authentication. However, when a user tries to create an account I am getting this error:

NameError (undefined local variable or method `devise_parameter_sanitizer' 

This is what my devise registrations controller looks like:

def sign_up_params
devise_parameter_sanitizer.for(:sign_up)
end

Any ideas?

Thanks in advance

4条回答
何必那么认真
2楼-- · 2019-04-18 03:50

For anyone who ends up here with error

undefined method `<<' for {}:ActionController::Parameters

you need to upgrade to Devise 3.1.0.rc as in this comment
which basically means using master branch version

gem 'devise', git: 'git://github.com/plataformatec/devise.git'

hope I help some lost souls as I was for last half an hour.

查看更多
来,给爷笑一个
3楼-- · 2019-04-18 03:51

The latest released Gem for Devise at the time of writing is 2.2.4. This does not include the devise_parameter_sanitizer method, hence the error you are seeing.

You are probably following the manual for Devise at https://github.com/plataformatec/devise. The section on Rails 4 and Strong Parameters has been added recently.

You have a few options:

  1. Get the latest master version of Devise using bundler, so that the devise_parameter_sanitizer method is available:

    gem 'devise', :git => 'git://github.com/plataformatec/devise.git'

  2. Don't apply ActiveModel::ForbiddenAttributesProtection to your User model, so strong parameters are not even used. More info here: Devise and Strong Parameters

  3. Override the required Devise controllers directly. See here: https://gist.github.com/kazpsp/3350730

查看更多
神经病院院长
4楼-- · 2019-04-18 03:56

Looking at the devise open issues on Github i found this: https://github.com/plataformatec/devise/issues/2372 - seem to do the trick for me. note that this is probably a rails 4 issue.

查看更多
ゆ 、 Hurt°
5楼-- · 2019-04-18 04:08

try to use rails4 branch

gem 'devise', github: 'plataformatec/devise', branch: 'rails4'
查看更多
登录 后发表回答