我正在使用 Heroku、Devise 和 Sendgrid。
这些是我的设置environment/production.rb
:
config.action_mailer.default_url_options = { :host => 'myapp.herokuapp.com' }
# ActionMailer Config
# Setup for production - deliveries, no errors raised
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
config.action_mailer.smtp_settings = {
address: "smtp.sendgrid.net",
port: 25,
domain: "myapp.herokuapp.com",
authentication: "plain",
user_name: ENV["SENDGRID_USERNAME"],
password: ENV["SENDGRID_PASSWORD"]
}
我已经ENV
很好地设置了 Heroku 上的变量,当我注册一个帐户时,它会正确地将电子邮件发送到正确的电子邮件地址。
只是当我单击确认链接时,我收到一堆错误并且没有确认帐户:
Started GET "/users/confirmation?confirmation_token=dZf6Jqc7x88q8tyH5bZp" for XX.XX.XX.XX at 2013-05-20 20:59:29 +0000
2013-05-20T20:59:29.413847+00:00 app[web.1]:
2013-05-20T20:59:29.413847+00:00 app[web.1]: NameError (uninitialized constant Confirmation):
2013-05-20T20:59:29.413847+00:00 app[web.1]:
编辑 1
这是我User.rb
的设计部分:
class User < ActiveRecord::Base
rolify
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :role_ids, :as => :admin
attr_accessible :name, :email, :password, :password_confirmation, :remember_me
编辑 2
这就是development.log
我做同样事情时发生的事情。
Started GET "/users/confirmation?confirmation_token=Gs3UYE2m6D84zfuXfa66" for 127.0.0.1 at 2013-05-20 17:12:39 -0500
Processing by ConfirmationsController#show as HTML
Parameters: {"confirmation_token"=>"Gs3UYE2m6D84zfuXfa66"}
Completed 500 Internal Server Error in 10ms
NameError - uninitialized constant Confirmation:
(gem) activesupport-3.2.13/lib/active_support/dependencies.rb:520:in `load_missing_constant'
我已经运行了所有的迁移,也许我需要为Confirmable
模块生成一个新的迁移?我怎么做?
编辑 3
这就是我的users
桌子的schema.rb
样子:
create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
t.string "encrypted_password", :default => "", :null => false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", :default => 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "name"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.float "sales_today"
t.float "sales_this_week"
t.float "sales_lifetime"
t.boolean "is_seller"
end
所以在我看来,该Confirmable
模块已全部设置完毕。
编辑 4
我忘记了我实际上确实覆盖了ConfirmationsController
:
class ConfirmationsController < Devise::ConfirmationsController
load_and_authorize_resource
protected
def after_confirmation_path_for(resource_name, resource)
if resource.has_role? :seller
new_item_path
else
root_path
end
end
end