Passing data with Rails' link_to helper

Posted by mathee on Stack Overflow See other posts from Stack Overflow or by mathee
Published on 2010-04-27T05:41:11Z Indexed on 2010/04/27 5:43 UTC
Read the original article Hit count: 431

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about haml