-1

I'm building a very simple rails app without resource routing. I haven't called trans_application_path but view returned an error undefined method `trans_application_path' for ...

here's my code. any ideas?

Controller

# GET /trans/drafts
  def drafts_index
    @trans_drafts = TransApplication.where(applied: false)
  end

# GET /trans/apps
  def apps_index
    @trans_apps = TransApplication.where(applied: true)
  end

View

<p id="notice"><%= notice %></p>

<h1>drafts_index</h1>

<table>
  <thead>
    <tr>
      <th>Name</th>
      <th>Department</th>
      <th>Month</th>
      <th>Applied</th>
      <th colspan="3"></th>
    </tr>
  </thead>

  <tbody>
    <% @trans_drafts.each do |trans_draft| %>
      <tr>
        <td><%= trans_draft.name %></td>
        <td><%= trans_draft.department %></td>
        <td><%= trans_draft.month %></td>
        <td><%= trans_draft.applied %></td>
        <td><%= link_to 'Show', trans_draft %></td>
      </tr>
    <% end %>
  </tbody>
</table>

<br>

What I've done

  • generated Scaffold
  • stop using resource routing and modified the controller.
kfs214
  • 63
  • 2
  • 8

1 Answers1

0
<td><%= link_to 'Show', trans_draft %></td>

There's you calling trans_application_path. link_to will use polymorphic_path for the url if you don't provide one. That will look at the class of the object it's given (trans_draft) and call the path helper for that class.

If you want the request to get to your controller you will need SOME route. If it's not the resource route (or equivalent), then pass the url you want into your link_to instead of the object.

Siim Liiser
  • 3,860
  • 11
  • 13
  • Thank you for your answer! I should have mentioned one thing. I tried deleting the all lines that include "link_to" but the problem wasn't solved... – kfs214 Dec 01 '20 at 07:54
  • look at the backtrace of the error. It will tell you which line produced the error. – Siim Liiser Dec 01 '20 at 09:21
  • Sorry, as I restarted the server, the problem was solved. It seems to be due to cache... – kfs214 Dec 08 '20 at 05:00