Ruby on rails 获取Rails观察器或清理器访问权,以从观察器中链接到字符串,或将视图渲染为字符串

Ruby on rails 获取Rails观察器或清理器访问权,以从观察器中链接到字符串,或将视图渲染为字符串,ruby-on-rails,routes,observer-pattern,link-to,Ruby On Rails,Routes,Observer Pattern,Link To,我配置了一个标准的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 =

我配置了一个标准的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
class TipObserver
是的,我知道这是作为一个清扫者设置的-它基本上与观察者相同,但是可以访问link_to方法,但是它似乎没有配置路由。轮廓路径和尖端路径方法为零

也许还有另一种方法可以做到这一点?也许是一个更“轨道方式”

如果有一种方法可以使用message.body的视图模板创建消息,那就太好了


有什么建议吗?

如果需要访问控制器外部的路由,请包括ActionController::UrlWriter模块