Reputation: 5953
I would like to have a 2nd show file for a table called locations. The file is views/locations/show2.html.erb
I've already added a 2nd index called index2.html.erb and I access it through
locations_index2_path
But, if I try something similar, it doesn't work:
location_show2_path(location)
I've also added this to the location controller:
def show2
@location = Location.find(params[:id])
end
Thanks!
UPDATE - I'm getting "Couldn't find Location without an ID" Parameters:
{"format"=>"14"}
URL:
http://localhost:5000/locations/show2.14
Routes:
get "locations/show2"
Locations Controller:
def show2
@location = Location.find(params[:id])
respond_to do |format|
format.html # show2.html.erb
format.json { render json: @location }
end
end
Link in index view:
<%= link_to 'Show', locations_show2_path(location), :class => 'btn btn-mini btn-success' %>
Upvotes: 0
Views: 161
Reputation: 15089
This new error means you are not passing an params[:id]
to your action on your controller. You can do this by adding information on your link:
<%= link_to 'Show', locations_show2_path(:id => location.id) %>
As show2
is a custom route, you have to specify what is the name of the parameter you are passing to the controller. Hope it helps.
Upvotes: 2