简体   繁体   English

Rails没有路线匹配控制器

[英]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.

相关问题 没有路线匹配{:action =&gt;“ update”,:controller =&gt;“”-Rails 5 - No route matches {:action=>“update”, :controller=>“” - Rails 5 Rails没有路由匹配{:controller =&gt;“devise / products”} - Rails No route matches {:controller=>“devise/products”} Rails控制器测试:ActionController :: UrlGenerationError:没有路由匹配 - Rails Controller Testing: ActionController::UrlGenerationError: No route matches 没有路线匹配,导轨使用错误的控制器? - No route matches, rails using wrong controller? Rails嵌套控制器-错误:没有路线匹配 - Rails nested controller - error: No route matches Rails:没有路线符合{:action =&gt;“ edit”,:controller =&gt;“ discussions” - Rails: No route matches {:action=>“edit”, :controller=>“discussions” Rails4 Rspec控制器测试没有路线匹配 - Rails4 Rspec Controller Tests No route matches 在rails / rspec中没有控制器的路由的“无路由匹配”错误 - “No route matches” error for route without a controller in rails/rspec Rails设计路由错误 - “无路由匹配”(controller =&gt;“devise / sessions”) - Rails Devise routing error - “No route matches” (controller=>“devise/sessions”) 没有路由匹配 {:action=&gt;&quot;comment&quot;, :id=&gt;&quot;1&quot;, :controller=&gt;&quot;posts&quot;} 在 rails - No route matches {:action=>"comment", :id=>"1", :controller=>"posts"} on rails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM