ユーザ認証にDeviseを使っています。メール認証(:confirmable)を有効化したいのですが、なぜかできません。
今のところサインアップやログインは全て可能ですが、メール認証だけができません。
解決方法か解決のヒントだけでも教えていただければ幸いです。
<やったこと>
gemにdeviseを入れる。
gem 'devise'
$ bundle install
$ bundle exec rails generate devise:install
送信メール設定
<config/environments/development.rb>
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => '',
:password => '',
:authentication => 'cram_md5',
:enable_starttls_auto => true
}
UserモデルにDeviseのメール認証用コラムを追加
<db/migrate/*****_devise_create_users.rb>
## Confirmable
t.string :confirmation_token
t.datetime :confirmed_at
t.datetime :confirmation_sent_at
t.string :unconfirmed_email
$rake db:create
Userモデルにdeviseメソッドの引数として:confirmableを指定。
<app/models/user.rb>
devise :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable, :trackable
routesファイルにdeviseを指定
<config/routes.rb>
devise_for :users
Sign up画面からユーザー登録するとメールが送信されずにいきなり認証済みでシステム内に入ってしまいます。
認証メールをスキップするskip_confirmation!を検索してもヒットしません。
$ grep -r skip_confirmation! *
Userのレコードを確認するとメール認証で入るべき項目が全てnilです。
[2] pry(main)> User.last
=> #<User id: 13, email: "[email protected]", encrypted_password: "...", sign_in_count: 1, current_sign_in_at: "2015-06-10 06:38:43", last_sign_in_at: "2015-06-10 06:38:43", confirmation_token: nil, confirmed_at: nil, confirmation_sent_at: nil, unconfirmed_email: nil, created_at: "2015-06-10 06:38:43", updated_at: "2015-06-10 06:38:43">
ログを確認するとメールを送信している様子は一切ありません。
[no_token] Processing by Users::RegistrationsController#create as HTML
[no_token] Parameters: {"utf8"=>"✓", "authenticity_token"=>"iLnOw9NgUzjUHOGmF7X2ejvlfxbjyNqSe4NNBZVbltE=", "user"=>{"name"=>"pozedi", "email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
[no_token] (0.6ms) BEGIN
[no_token] User Exists (0.7ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = '[email protected]' LIMIT 1
[no_token] User Exists (0.8ms) SELECT 1 AS one FROM "users" WHERE ("users"."email" = '[email protected]' AND "users"."deleted_at" IS NULL) LIMIT 1
[no_token] User Load (0.9ms) SELECT "users".* FROM "users" WHERE "users"."deleted_at" IS NULL AND "users"."auth_token" = '3TF5yoyxZjJdsKz12d-u' ORDER BY "users"."id" ASC LIMIT 1
[no_token] SQL (0.8ms) INSERT INTO "users" ("auth_token", "created_at", "email", "encrypted_password", "metadata", "name", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["auth_token", "3TF5yoyxZjJdsKz12d-u"], ["created_at", "2015-06-10 06:38:43.365969"], ["email", "[email protected]"], ["encrypted_password", "$2a$10$3GLpAyPdHupojLx2fRF4aO4PxCWLcJ/MTx6n.T3qNOapXd2OQgUIu"], ["metadata", "{}"], ["name", "pozedi"], ["updated_at", "2015-06-10 06:38:43.365969"]]
[no_token] (0.9ms) COMMIT
[no_token] (0.6ms) BEGIN
[no_token] SQL (1.0ms) UPDATE "users" SET "current_sign_in_at" = $1, "current_sign_in_ip" = $2, "last_sign_in_at" = $3, "last_sign_in_ip" = $4, "metadata" = $5, "sign_in_count" = $6, "updated_at" = $7 WHERE "users"."id" = 13 [["current_sign_in_at", "2015-06-10 06:38:43.417435"], ["current_sign_in_ip", "127.0.0.1/32"], ["last_sign_in_at", "2015-06-10 06:38:43.417435"], ["last_sign_in_ip", "127.0.0.1/32"], ["metadata", "{}"], ["sign_in_count", 1], ["updated_at", "2015-06-10 06:38:43.431023"]]
[no_token] (1.0ms) COMMIT
[no_token] Redirected to http://localhost:3000/users/13
[no_token] Completed 302 Found in 310ms (ActiveRecord: 7.3ms)
なぜでしょうか!?