Mark charlton
Mark charlton

Reputation: 377

NameError (undefined local variable or method `devise_parameter_sanitizer'

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

Upvotes: 20

Views: 4293

Answers (4)

Mike Szyndel
Mike Szyndel

Reputation: 10593

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.

Upvotes: 2

Fivell
Fivell

Reputation: 11929

try to use rails4 branch

gem 'devise', github: 'plataformatec/devise', branch: 'rails4'

Upvotes: 6

Tony Marklove
Tony Marklove

Reputation: 11

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

Upvotes: 1

Elad Meidar
Elad Meidar

Reputation: 814

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.

Upvotes: 3

Related Questions