標準の Rails オブザーバーを構成しています。
class TipObserver < ActionController::Caching::Sweeper
observe Tip
def after_save(tip)
profile_link = link_to tip.profile.name, profile_path(tip.profile)
Profile.followers(tip.quality).each{|profile|
message = Message.new
message.sender = Profile.first
message.recipient = profile
message.subject = "New Tip #{tip.name}"
tip_link = link_to tip.name, tip_path(tip)
message.body = "Hey #{profile.name}\n Here is a tip for you..#{tip_link} from #{profile_link}"
message.save!
}
end
end
はい、これがスイーパーとして設定されていることは知っています。基本的にはオブザーバーと同じですが、link_to メソッドにアクセスできますが、ルートが構成されていないようです。profile_path および tip_path メソッドは nil です。
おそらくこれを達成する別の方法がありますか?おそらくもっと「Rails Way」ですか?
message.body のビュー テンプレートを使用してメッセージを作成する方法があれば、非常に便利です。
助言がありますか?