2

I'm really new to ruby and coming from a php background.

But I want to create a link to a path and add an extra parameter on the end of the path.

Here's what I have:

<%= link_to 'View Answers', quiz_path(@quiz "answers=true") %>

with out the answers=true the link resolves to http://localhost:3000/quizzes/3, which is as expected and works fine. But when I add the answers=true i get http://localhost:3000/quizzes/3.answers=true.

This is so close. But of course I need the . to be a ?.

Obviously I not doing this quite right, but if can help me with a simple a solution about how to add an extra parameter in the link url I would be grateful.

2 Answers 2

1

<%= link_to 'View Answers', quiz_path(quiz: @quiz, answers: true) %>

You could try the same thing just removing the quiz: part (so it's (@quiz, answers:true)), but I think the above should work.

0

Try

<%= link_to 'View Answers', quiz_path(@quiz), :answers => "true"  %>

From http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to

Example:

link_to "Ruby on Rails search", :controller => "searches", :query => "ruby on rails"

    # => <a href="/searches?query=ruby+on+rails">Ruby on Rails search</a>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.