Alex Kinsbrunner
Alex Kinsbrunner

Reputation: 111

Devise error undefined method `email'

I have tried tuning my Devise views and have replaced email by username. For sure, I have adjusted initializers/devise.rb by replacing all the occurences of :email by :username. I adjusted screens and things were working fine until I tried to delete the field email from database.

After having done this, I am still able to login and create accounts as desired by using my new key (username), yet, when trying to update the user, I am getting this error message stating that email method is not defined.

I understand that I am missing a place from where to take a call to this non-existing attribute/method but, I don't know where....

Some logs:

NoMethodError in Devise::RegistrationsController#update
undefined method `email' for #<User...

Rails.root: /vagrant/src/projectX

Application Trace | Framework Trace | Full Trace
activemodel (4.0.1) lib/active_model/attribute_methods.rb:439:in `method_missing'
activerecord (4.0.1) lib/active_record/attribute_methods.rb:155:in `method_missing'
activemodel (4.0.1) lib/active_model/validator.rb:151:in `block in validate'
activemodel (4.0.1) lib/active_model/validator.rb:150:in `each'
activemodel (4.0.1) lib/active_model/validator.rb:150:in `validate'
activerecord (4.0.1) lib/active_record/validations/presence.rb:5:in `validate'
activesupport (4.0.1) lib/active_support/callbacks.rb:283:in `_callback_before_13'
activesupport (4.0.1) lib/active_support/callbacks.rb:377:in `_run__265703777__validate__callbacks'
activesupport (4.0.1) lib/active_support/callbacks.rb:80:in `run_callbacks'

Upvotes: 3

Views: 2489

Answers (2)

DWin
DWin

Reputation: 31

For anyone finding this, I was trying to create a Devise user type that isn't authenticated by email and password.

If you're in the same boat, remove the following from your model: :validatable :database_authenticatable,

These two expect there to be an email and password to validate and authenticate against. Removing them ensures the checks related to either aren't used.

Upvotes: 0

Alex Kinsbrunner
Alex Kinsbrunner

Reputation: 111

Just needed to adjust User model adding the following:

def email_required? false end

def email_changed? false end

Upvotes: 1

Related Questions