Ruby on rails 3 Rails添加第二个显示视图

Ruby on rails 3 Rails添加第二个显示视图,ruby-on-rails-3,Ruby On Rails 3,我想要一个名为locations的表的第二个显示文件。 该文件是views/locations/show2.html.erb 我已经添加了第二个索引index2.html.erb,我可以通过 locations_index2_path 我有一条叫做“获取位置/索引”的路线 但是,如果我尝试类似的方法,它不会起作用: location_show2_path(location) 我还将此添加到位置控制器: def show2 @location = Location.find(para

我想要一个名为locations的表的第二个显示文件。 该文件是views/locations/show2.html.erb

我已经添加了第二个索引index2.html.erb,我可以通过

 locations_index2_path
  • 我有一条叫做“获取位置/索引”的路线
但是,如果我尝试类似的方法,它不会起作用:

location_show2_path(location)
我还将此添加到位置控制器:

def show2
  @location = Location.find(params[:id])
end
 def show2
  @location = Location.find(params[:id])

  respond_to do |format|
    format.html # show2.html.erb
    format.json { render json: @location }
  end
end
谢谢

更新-我得到“没有ID找不到位置” 参数:

{"format"=>"14"}
网址:

路线:

  get "locations/show2"
位置控制器:

def show2
  @location = Location.find(params[:id])
end
 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' %>
“btn btn迷你btn成功”%>

此新错误意味着您没有将
参数[:id]
传递给控制器上的操作。您可以通过在链接上添加信息来完成此操作:

 <%= link_to 'Show', locations_show2_path(:id => location.id) %>
location.id)%%>

由于
show2
是自定义路由,因此必须指定要传递给控制器的参数的名称。希望有帮助。

您是否将路线添加到了show2中?仍然收到错误-我更新了我的问题。