title: Rails dataTables add link_to
body: <p>I'm using an approach from Railscast to remotely access a table for dataTables.</p>
  
  <p>This is the start of the code in workorders4_datatable.rb:</p>
  
  <pre><code>class Workorders4Datatable
  
  delegate :params, :h, :link_to, :number_to_currency, to: :@view
  
  def initialize(view)
    @view = view
  end
  
  def as_json(options = {})
    {
        sEcho: params[:sEcho].to_i,
        iTotalRecords: Workorder.external.count,
        iTotalDisplayRecords: workorders.external.total_entries,
        aaData: data
    }
  end
  
  private
  
  def data
    workorders.external.map do |workorder|
      [
          link_to(workorder.id, workorder),
          h(workorder.parent.try(:id)),
          h(workorder.description),
          h(workorder.client.try(:client_name)),
          h(workorder.woasset.try(:assetnum)),
          h(workorder.type.try(:typecode)),
          h(workorder.billmethod.try(:method_name)),
          h(workorder.workgroup.try(:group_name)),
          h(workorder.employee.try(:employee_full_name)),
          h(workorder.wostatus.try(:statuscode)),
          h(workorder.expenses.tobill.sum("quantity") * workorder.expenses.sum("unitcost")),
          h(workorder.events.tobill.sum("hours")),
          h(workorder.events.sum("hours")),
          link_to('ADD Invoice', new_invoice_path(:workorder_id =&gt; workorder), :class =&gt; 'btn btn-primary')
      ]
    end
  end
  </code></pre>
  
  <p>All of it works except for this line:</p>
  
  <pre><code>link_to('ADD Invoice', new_invoice_path(:workorder_id =&gt; workorder), :class =&gt; 'btn btn-primary')
  </code></pre>
  
  <p>It causes this error:</p>
  
  <pre><code>NoMethodError - undefined method `new_invoice_path' for #&lt;Workorders4Datatable:0x007f94513588a0&gt;:
  </code></pre>
  
  <p>Yet, the following works in a different view:</p>
  
  <pre><code>&lt;%= link_to 'ADD Invoice', new_invoice_path(:workorder_id =&gt; @workorder.id), :class =&gt; 'btn btn-primary' %&gt;
  </code></pre>
  
  <p>Is there some way I can get it to work?</p>