我想有一个名为位置表的第二个显示文件。文件是views/locations/show2.html.erb
我已经添加了第二个索引index2.html。我通过
访问它 locations_index2_path
- 和我有一个名为get "locations/index2"的路由
但是,如果我尝试类似的东西,它不起作用:
location_show2_path(location)
我还添加了这个到位置控制器:
def show2
@location = Location.find(params[:id])
end
谢谢!
更新-我得到"无法找到位置没有ID"参数:
{"format"=>"14"}
URL: http://localhost:5000/locations/show2.14
路线:
get "locations/show2"
位置控制器:
def show2
@location = Location.find(params[:id])
respond_to do |format|
format.html # show2.html.erb
format.json { render json: @location }
end
end
索引视图中的链接:
<%= link_to 'Show', locations_show2_path(location), :class => 'btn btn-mini btn-success' %>
这个新的错误意味着您没有将params[:id]
传递给控制器上的操作。你可以在你的链接上添加信息:
<%= link_to 'Show', locations_show2_path(:id => location.id) %>
由于show2
是自定义路由,您必须指定要传递给控制器的参数的名称。