Rails 4.0.3アプリでDevise 3.2.3を使用しています
私のユーザー モデルにはafter_create: subscribe
、新しいユーザーをニュースレターに登録するコールバックがあります。このコールバックを導入した後、新しいユーザーがメールを確認しようとするたびにconfirmation token is invalid
メッセージが表示されます。それにもかかわらず、再送確認メールからの確認リンクは機能します。
明らかにコールバックの使用を避けることができ:after_create
ますが、それは非常に苦痛です。
User.rb:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :trackable, :validatable,
:confirmable, :rememberable
has_many :things
belongs_to :city
validates_presence_of :city_id
validates :email, :presence => true, :email => true
after_create :subscribe
def subscribe(frequency = :weekly)
if [:weekly, :monthly].include? frequency
response = Rails.configuration.mailchimp.lists.subscribe({
id: get_list_id(frequency),
email: { email: email },
merge_vars: { HASH: hashify(frequency), USER_ID: id }, # generate approptiate hash
double_optin: false
})
# response
end
update_attributes(newsletter_frequency: frequency.to_s)
response
end
end