link_to app文件夹里面的文件rails 3.2.8

时间:2012-11-29 18:17:35

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.1 link-to

我在/app/datatables/admin/

中有一个名为 messages_datatables.rb 的文件
class Admin::MessagesDatatable
  delegate :params, :h, :link_to, :number_to_currency, to: :@view
  .
  .
  .
  private
  def data
    messages.map do |message|
      [
        "", 
        link_to(message.subject, admin_message_path(message))
      ]
    end
  end
  .
  .
  .
  .
end

我需要在此文件中使用link_to帮助器,但我得到:

NoMethodError (undefined method `admin_message_path' for #<Admin::MessagesDatatable:0xbe07170>):

路径在视图中正常工作。我的路线上有路径。

我的错误在哪里?

1 个答案:

答案 0 :(得分:1)

添加:

delegate :url_helpers, to: 'Rails.application.routes'

而不是admin_message_path,请使用url_helpers.admin_message_path