私は devise_invitable を使用して、ユーザーがお互いに招待できるようにしています。招待が作成されたとき、または招待が受け入れられたときに、ユーザーの値を設定したいと考えています。1つのアプローチはここにあります
Ruby on Railsでユーザーをグループに追加するためにdevise_invitableを使用していますか?
しかし、これはやり過ぎのようです。コールバックは完璧な解決策のように見えますが、私の 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 のドキュメントは少しわかりにくいと思います。
ありがとう!