Passing data with Rails' link_to helper
- by mathee
I am implementing a question-and-answer application with Ruby on Rails. I have MVCs for Questions and Answers.
In the home view (index.haml), I list the Questions like this:
- @questions.each do |q|
%tr
%td
=link_to q.title, q
Next to each of those, I want to add a link that will create a new Answer and pass the id of the Question in that row (continued from the above Haml code) :
%td
#{link_to 'answer me!', new_answer_path, pass q.id here somehow?}
I don't know how to properly pass it and then access it in AnswersController.
I tried #{link_to 'answer me!', new_answer_path, :question_id => q.id}, but that was just a guess, and I don't know how to access that in AnswersController.
I read the Rails API docs, and I know you can add query, too, but I still don't know how to access the value in AnswersController.