2012-02-02 5 views
15

私はRails 3を使用しています。hereが重複している可能性があります。しかし、それは私の問題を解決しなかったし、他の解決策もしなかった。私はUserモデルにdevise :confirmableを追加したん未定義のローカル変数またはメソッド `confirmed_at 'for#ユーザ

class AddConfirmableToDevise < ActiveRecord::Migration 
    def change 
    change_table(:users) do |t| 
     t.confirmable 
    end 
    add_index :users, :confirmation_token, :unique => true 
    end 
end 

を次のように

私の移行があります。

私のrake db:migrateは出力しません。そして私の看板アップページがエラーを与える:

undefined local variable or method 'confirmed_at' for #User 

誰もが手掛かりを持っていますか?

+2

あなたが知っておくべきこと開発者のマイグレーションヘルパー( 't.confirmable'のような)は廃止されました。バージョン2.0。これからは、[列を手動で追加する](https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style) –

答えて

21

私はそれを解決した。移行は古くなっています。同じコードで別の名前で新しい移行を生成します。

1.Runコマンド:移行ファイル2.In

rails g migration add_confirmable_to_devise_v1 

class AddConfirmableToDeviseV1 < ActiveRecord::Migration 
    def change 
    change_table(:users) do |t| 
     t.confirmable 
    end 
    add_index :users, :confirmation_token, :unique => true 
    end 
end 

3.Then

rake db:migrate 
4

私はMongoidを使用し、これと同じエラーを得ましたよ。私はこれらのフィールドを追加し、rspecが私の16の例で緑色になるようにしました。

field :confirmation_token, :type => String 
field :confirmed_at,   :type => Time 
field :confirmation_sent_at, :type => Time 
field :unconfirmed_email, :type => String 
13

自分自身に注意してください。誰かがそれが役に立つかもしれません:

rake db:migrate:reset 
    rake db:reset 

出来上がり:我々は必要なもの は、以下の2つのコマンドであります!できます! DevDudeの@で結ぶこと

+1

とは何ですか? 'db:reset'と' rake db:migrate:reset'ですか? 'rake -D db:reset'または' rake -D db:migrate:reset'は何も表示されません... – Green

18

最新工夫のとおり、あなただけの工夫のユーザーの移行上の次の行からコメントを削除する必要がありますが...(2013 ....._ devise_create_users.rb)

# Confirmable 
    t.string :confirmation_token 
    t.datetime :confirmed_at 
    t.datetime :confirmation_sent_at 
    t.string :unconfirmed_email # Only if using reconfirmable 
14

受け入れ答えに答える - あなたはすでにあなたが確認できる追加する必要があるために、既存のUsersモデルを持っている場合は、4月14日のよう工夫電流のバージョンのための完全な移行コードは次のとおりです。

class AddConfirmableToDeviseV1 < ActiveRecord::Migration 
    def change 
    change_table(:users) do |t| 
     # Confirmable 
     t.string :confirmation_token 
     t.datetime :confirmed_at 
     t.datetime :confirmation_sent_at 
     t.string :unconfirmed_email # Only if using reconfirmable 
    end 
    add_index :users, :confirmation_token, :unique => true 
    end 
end 
+0

はい、これは正解です。実際に、最初にdeviseの移行を生成すると、これはコメントアウトされます。 – Donato

関連する問題