我覆盖设计的确认!方法来发送一个值得欢迎的消息,我的用户:devise_invitable:邀请后确认
class User < ActiveRecord::Base
devise :invitable, :database_authenticatable, :registerable, :recoverable,
:rememberable, :confirmable, :validatable, :encryptable
# ...
# Devise confirm! method overriden
def confirm!
UserMailer.welcome_alert(self).deliver
super
end
end
随着devise_invitable当用户接受邀请,并设置自己的密码确认!方法永远不会触发,是否有可能强制它? devise_invitable如何确认用户?
或者我可以用相同的方式覆盖accept_invite(或其他所谓的)方法吗?
我希望受邀用户保持未经确认,然后在接受邀请后确认。
谢谢,非常感谢任何帮助!
UPDATE
翻翻devise_invitable model我发现这两种方法谁可能会导致此不良行为:
# Accept an invitation by clearing invitation token and confirming it if model
# is confirmable
def accept_invitation!
if self.invited? && self.valid?
self.invitation_token = nil
self.save
end
end
# Reset invitation token and send invitation again
def invite!
if new_record? || invited?
@skip_password = true
self.skip_confirmation! if self.new_record? && self.respond_to?(:skip_confirmation!)
generate_invitation_token if self.invitation_token.nil?
self.invitation_sent_at = Time.now.utc
if save(:validate => self.class.validate_on_invite)
self.invited_by.decrement_invitation_limit! if self.invited_by
!!deliver_invitation unless @skip_invitation
end
end
end
想通了:https://gist.github.com/982181 – 2011-05-20 01:39:13