Darkisa
Darkisa

Reputation: 2047

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:

enter image description here

but I keep getting the following error:

enter image description here

Why is it saying that no route matches :action => show and :controller=>"test_results when according to my routes it does exist?

Upvotes: 0

Views: 388

Answers (2)

jvillian
jvillian

Reputation: 20253

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

Upvotes: 1

user229044
user229044

Reputation: 239551

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)

Upvotes: 1

Related Questions