I'm using Devise 3.2.3 on a Rails 4.0.3 app
In my user model I have an after_create: subscribe
callback that subscribes a new user to a newsletter. After I introduced this callback every time a new user attempts to confirm their email they get confirmation token is invalid
message. Nevertheless confirmation link from the resend confirmation email works.
I can obviously avoid using the :after_create
callback, but that's quite painful.
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