如何使用Observer模型钩子中的polymorphic_path(rails4)

时间:2015-07-10 20:11:45

标签: ruby-on-rails observers urlhelper

我可以在控制台中使用app.polymorphic_path(MyModel.first)。 但没有什么能像那样:

class ModelsObserver < ActiveRecord::Observer
  observe :my_model, :my_model2
  def publish_data(rec) # rec is a model instance
     amqp_publish({
      # ...
      # show_path: Rails.application.helpers.polymorphic_path(rec)
      # show_path: ActionDispatch::Routing::PolymorphicRoutes.polymorphic_path(rec)
      show_path: application.polymorphic_path(rec)
    })

0 个答案:

没有答案
相关问题