8

Userモデルは、このようなSTHに見える報告工夫ensure_authentication_tokenは、未定義のメソッド

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 

config.token_authentication_key = :auth_token 

私のユーザーの移行は次のようになります

ユーザーを作成するときに、パラメータを入力すると、

{"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"} 

しかし、ユーザーの作成中に、まだ私はエラーを次取得:私はここで間違って

NameError in Devise::RegistrationsController#create 

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

何をやっていますか?

P.S.私のGemfileでは、宝石を考案、次のように設定されている:それは私の悪かった

gem 'devise', :git => 'git://github.com/plataformatec/devise.git', :branch => 'master' 
+0

モデルに 'before_save:ensure_authentication_token'という行があるのはなぜですか?根拠は何ですか? – clyfe

+0

私はそれがユーザークラスにある必要があることがわかったリソースによると。だから、私はモデルにとどまっています。 –

+0

どのようなリソースがありますか?私はそれが原因であると信じています。もしあなたがそれを取り除くと、エラーは消え去りますが、問題は "何が意味ですか?"です。 – clyfe

答えて

10

は申し訳ありませんが、私はカンマを逃した:)今働い

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

その。

+0

LoLを返します。私が遭遇したのと同じ正確な問題。本当にありがとう。 – sivabudh

+1

笑!私は知っている、時々あなたはこれのような小さなもので立ち往生し、バックトレースのバグについての適切な情報を得ることができません。バックトレースはよりユーザーフレンドリーでスマートだったと思います。しかし、とにかく、私はあなたが不具合を発見してうれしいです。 ;) –

+0

私はちょうど私に起こった非常に同じことを信じることができません。 – Puce