2012-12-26 72 views
0

我想有一个名为locations的表的第二个显示文件。 该文件的意见/位置/ show2.html.erbRails添加第二个显示视图

我已经添加了第二个指数叫index2.html.erb和我通过

locations_index2_path 
  • 访问它,我有一个路线名为get “位置/索引2”

但是,如果我尝试类似的东西,这是行不通的:

location_show2_path(location) 

我还添加了这位置控制器:

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

谢谢!

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

{"format"=>"14"} 

网址:

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' %> 
+0

您是否将路线添加到show2? – MurifoX

+0

仍然收到错误 - 我更新了我的问题。 – Reddirt

回答

2

这个新的错误意味着你不及格的params[:id]到你的动作控制器上。您可以通过添加你的链接信息做到这一点:

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

由于show2是一个自定义路线,你必须指定哪些是要传递给控制器​​的参数的名称。希望能帮助到你。

+0

谢谢!工作很好。 – Reddirt

相关问题