Sri
Sri

Reputation: 2273

how to find the value by param id in View?

I have a field in the View like,

<%= f.text_field :question_id, class: "cross-reference-question-value"  %>

Now, I tried to use this question_id that match the other column from the same table like the following:

<%= text_field :question_id, Question2009.all.map{|an| [an.answer_table]} %>

I could get all the values here from that table. But, I just need to get the value that match the params of question_id.

Upvotes: 1

Views: 345

Answers (1)

Salil
Salil

Reputation: 47472

Change

<%= text_field :question_id, Question2009.all.map{|an| [an.answer_table]} %>

To

<%= text_field :question_id, Question2009.where("question_id=?", params[:question_id]).map{|an| [an.answer_table]} %>

Upvotes: 3

Related Questions