Sri ganesh K
2012-Oct-10 22:54 UTC
How to get the value of association column name in ruby on rails?
If i have two models like Question and Answer. Question has three columns like question_id, question_type, question_text and Answer has three values answer_id, question_id, answer_text. I am creating form for the Answer model. Example: <%= f.text_field :question_id %>. <%= f.hidden_field :question_id %>. Here, I am using the hidden field to find the question_type. I tried the map method, but that doesn''t work. So Somebody help me to get the question_type value by the selection of thatquestion_id. Thanks -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/OcaCarF70bkJ. For more options, visit https://groups.google.com/groups/opt_out.
Colin Law
2012-Oct-11 07:48 UTC
Re: How to get the value of association column name in ruby on rails?
On 10 October 2012 23:54, Sri ganesh K <srickganesh-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> If i have two models like Question and Answer. Question has three columns > like question_id, question_type, question_text and Answer has three values > answer_id, question_id, answer_text.Question should generally not have a question_id field, it should just have the default id field. Unless that is you have some unusual requirements.> > I am creating form for the Answer model. > > Example: > > <%= f.text_field :question_id %>. > <%= f.hidden_field :question_id %>. > > Here, I am using the hidden field to find the question_type. I tried the map > method, but that doesn''t work. So Somebody help me to get the question_type > value by the selection of thatquestion_id.You have not shown us the relationship between the models (has_many, belongs_to or whatever). That information is critical to answering the question. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.