2012-12-26 74 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

相關問題