我正在使用 devise_invitable 允许用户互相邀请。我想在创建邀请或接受邀请时为用户设置值。一种方法在这里
使用 devise_invitable 将用户添加到 Ruby on Rails 中的组?
但这似乎有点矫枉过正。回调看起来像是一个完美的解决方案,但在我的 Rspec 测试期间它们似乎没有触发。
这是用户模型:
class User < ActiveRecord::Base
belongs_to :company
rolify
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :invitable, :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, :company
validates :company, :presence => true
after_invitation_accepted :email_invited_by
before_invitation_accepted :email_invited_by
private
def email_invited_by
# This is NEVER executed during tests, even when an invite is successfully accepted
puts "Callback worked"
end
end
任何关于在哪里看的线索将不胜感激。我发现 devise_invitable 文档有点不透明。
谢谢!