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
<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.