我在現有的Rails控制器(reports_controller)中添加了一個方法來處理超出REST基本範圍的特定操作。讓我們把這一行動「細節」:link_to在Rails中不包含對象的ID 2.3.8
def detail
@report = Report.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @report }
end
末
我添加了相應的佈局頁面(detail.html.erb)和路由,以確保我可以從任何地方訪問該頁面。這是我的路線如何:
map.connect "reports/:action", :controller => 'reports', :action => /[a-z]+/i
現在我可以訪問任何詳細信息頁面。一個例子頁面是這樣的:http://127.0.0.1:3000/reports/detail/8
現在,我試圖創建從主報告索引頁的詳細信息頁面的鏈接,而是使用下面的代碼時:
<%= link_to "Details", {:controller => "reports", :action => "detail", :id => @report }, {:title => "see details for this report"} %>
鏈接這是創建不包括報告的ID上它看起來像這樣:
http://127.0.0.1:3000/reports/detail
任何想法,我在做什麼錯?
謝謝!
也沒有工作。我已經手動創建了這個URL,這是唯一在這一點上工作的...... – wotaskd 2010-11-20 02:40:35
'link_to'會有所不同。我會編輯我的答案。 – 2010-11-20 02:42:21
啊,謝謝!現在錯誤似乎不同,似乎與我的路線有關。我只在我原來的問題上提供了一行,加上你的建議(:member)。這是錯誤:
– wotaskd 2010-11-20 14:53:53