【发布时间】:2016-05-13 18:01:36
【问题描述】:
在我的 Rails 应用程序中导航时出现以下错误: 没有路线匹配
{:action=>"startnew", :controller=>"tickets", :ticket_id=>4} missing required keys: [:id]
问题是,我有一条路线:
post 'tickets/:id/startnew' => 'tickets#startnew', as: :start_new
当我导航到 URL http://localhost:3000/tickets 时,这很好用
但是当我加载 URL http://localhost:3000/tickets?id=4 时会发生错误,在我的情况下它需要工作,因为我在tickets#index 上的两个部分中呈现了tickets#list 和tickets#show,其中发生了上述错误。
当我单击不同页面上的链接时,tickets#index 被加载,并且仅当我在 url (http://localhost:3000/tickets?id=4) 中有参数时才会呈现tickets#show。
在节目中我有这部分,这会导致问题:
<%= link_to 'Book time', start_new_path(ticket_id: @ticket.id), method: :post, class: "button info block-shadow-info text-shadow", remote: true %>
你能不能给我一个提示!
【问题讨论】:
-
把参数里的
:ticket_id改成:id,或者把路由改成post 'tickets/:ticket_id/startnew' => 'tickets#startnew', as: :start_new -
你能运行
rake routes | grep start并分享结果吗?
标签: ruby-on-rails url routing