Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise ensure_authentication_token reports undefined method

User model looks sth like this:

before_save :ensure_authentication_token

devise :database_authenticatable, :registerable,
  :recoverable, :rememberable, :trackable, :validatable
  :token_authenticatable

attr_accessible :email, :password, :password_confirmation, 
                :remember_me, :first_name, :last_name, 
                :cell_phone, :city, :state, :country, :user_type

In devise.rb file I have uncommented:

config.token_authentication_key = :auth_token

My user migration looks like:

class DeviseCreateUsers < ActiveRecord::Migration
  def self.up
   create_table(:users) do |t|
    t.database_authenticatable :null => false
    t.recoverable
    t.rememberable
    t.trackable
    t.token_authenticatable
    t.timestamps
   end

   add_index :users, :email,                :unique => true
   add_index :users, :reset_password_token, :unique => true
   add_index :users, :authentication_token, :unique => true
  end

  def self.down
   drop_table :users
  end
end

While creating a user, following parameters comes

{"utf8"=>"✓",
 "authenticity_token"=>"+F8cjCoauVKhZPSJLhW+AAhui1DygBcODsYn4Va/ktY=",
 "user"=>{"first_name"=>"any_name",
 "last_name"=>"any_name",
 "email"=>"[email protected]",
 "password"=>"[FILTERED]",
 "password_confirmation"=>"[FILTERED]",
 "cell_phone"=>"any_number",
 "city"=>"some_city",
 "state"=>"some_state",
 "country"=>"U.S.A",
 "user_type"=>"student"},
 "commit"=>"Sign up"}

But still I get following error while creating user:

NameError in Devise::RegistrationsController#create

   undefined local variable or method `ensure_authentication_token' for #<User:0x007fd4448f7350>

What I'm doing wrong here?

P.S. In my Gemfile, Devise gem is configured as follows:

gem 'devise', :git => 'git://github.com/plataformatec/devise.git', :branch => 'master'
like image 695
Manish Das Avatar asked Jan 03 '12 18:01

Manish Das


1 Answers

Sorry it was my bad, I missed a comma :)

devise :database_authenticatable, :registerable,
  :recoverable, :rememberable, :trackable, :validatable, #here
  :token_authenticatable

Its working now.

like image 197
Manish Das Avatar answered Oct 21 '22 12:10

Manish Das