Search code examples
ruby-on-railsrubyruby-on-rails-3ruby-on-rails-3.1link-to

link_to inside file inside app folder rails 3.2.8


I have a file called messages_datatables.rb inside /app/datatables/admin/

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

I need use link_to helper inside this file but I get:

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

The path is working fine in views. I have the path in my routes.

Where have I the error?


Solution

  • Add:

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

    And instead of admin_message_path, use url_helpers.admin_message_path