我正在爲練習創建聚會規劃應用程序,並遇到了一些麻煩。我需要能夠在點擊時顯示我的特定聚會,但似乎並不奏效。我得到這個錯誤:重定向到節目,但無法在Ruby中找到ID參數
未定義的方法`show_party_path」爲#<#:0x007fb115660620>
我在各方控制器定義的顯示方法是這樣的:
def show
@party = Party.find(params[:id])
end
index.html.erb
<table>
<tr>
<% @parties.each do |party| %>
<tr>
<td><p><%= link_to party.title, show_party_path(@party) %></p></td>
<td><p><%= party.start_time %></p></td>
<td><p><%= party.end_time %></p></td>
<td><p><%= party.address %></p></td>
<td><p><%= party.city %></p></td>
<td><p><%= party.state %></p></td>
<td><p><%= party.zipcode %></p></td>
<td><p><%= party.phone %></p></td>
<td><p><%= party.email %></p></td>
<td><p><%= party.url %></p></td>
<td><%= link_to "Remove", party, method: :delete, data: { confirm: "Are you sure?" } %></td>
</tr>
<% end %>
</tr>
</table>
<%= link_to "New Party", new_party_path %>
Interstingly,當我點擊節目時,它也有一個奇怪的網址。它從localhost:3000到localhost:3000/parties。它沒有指定實際的參與者ID。在沒有輸入參數的情況下,節目將如何知道顯示哪一方?
任何幫助,非常感謝。
我的路線:
Prefix Verb URI Pattern Controller#Action
parties GET /parties(.:format) parties#index
POST /parties(.:format) parties#create
new_party GET /parties/new(.:format) parties#new
edit_party GET /parties/:id/edit(.:format) parties#edit
party GET /parties/:id(.:format) parties#show
PATCH /parties/:id(.:format) parties#update
PUT /parties/:id(.:format) parties#update
DELETE /parties/:id(.:format) parties#destroy
root GET / parties#index
最佳, 埃裏克
使用'耙routes'顯示您的可用路徑。 'show'派對路徑默認爲'party_path(@party)'。 – pierallard 2015-04-03 16:25:34
如果rake路由中的格式是party GET /parties/:id(.:format)parties#show does not mean show需要localhost:3000/parties/party_id的url嗎?如何更改網址以包含party_id? – 2015-04-03 16:33:00
正如ForgetTheNorm所示:'party_path(@party)'會將id添加到url – Klaus 2015-04-03 16:38:45