[英]Rails no route matches controller
I am trying to pass both a user id, and a test id to a controller using link_to. 我正在尝试使用link_to将用户ID和测试ID传递给控制器。 Below is my code: 下面是我的代码:
<%= link_to(test.name, user_test_result_path(:userd_id => 1, protocol.id)) %>
and below are my routes: 以下是我的路线:
but I keep getting the following error: 但我不断收到以下错误:
Why is it saying that no route matches :action => show and :controller=>"test_results when according to my routes it does exist? 为什么根据我的路由,它确实不存在匹配:action => show和:controller =>“ test_results的路由?
You shouldn't be passing a hash to your path helper. 您不应该将哈希传递给路径帮助器。 If your path has two segments, :user_id
and :id
, you would simply invoke helper_name(user_id, id)
, not helper_name(user_id: user_id, id)
. 如果路径有两个段:user_id
和:id
,则只需调用helper_name(user_id, id)
,而不是helper_name(user_id: user_id, id)
。
In your case you should be calling 就您而言,您应该打电话给
user_test_result_path(1, protocol.id)
Dude. 杜德 It says userd_id
here: 它在这里说userd_id
:
<%= link_to(test.name, user_test_result_path(:userd_id => 1, protocol.id)) %>
Spelling matters! 拼写很重要!
Also, where is that: 另外,在哪里:
{9=>2...}
coming from in your params? 来自您的参数? I'm guessing you'll have more luck if you do something like: 我猜测如果您执行以下操作,您会更加幸运:
<%= link_to(test.name, user_test_result_path(id: protocol.id, user_id: 1)) %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.