简体   繁体   中英

Rails no route matches controller

I am trying to pass both a user id, and a test id to a controller using link_to. 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?

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) .

In your case you should be calling

user_test_result_path(1, protocol.id)

Dude. It says userd_id here:

<%= 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)) %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM