Rails - access to model attributes in forms

How do I access the parent attribute of a model in a form? For example, for the following response form, I want to access answer.question.text and use this for a question - how to do it?

Thanks!

<% form_for :answers do |ans| %> <%= ans.label :question, "Question" %> <%= ans.text_field :value %> 
+4
source share
2 answers

I ended up using ans.object.question.text - I didn’t know that you could do form.object! Wow!

+6
source

Have you tried ans.question.text ? You may need to make sure that the question is already loaded with :include => question in your search appliance.

0
source

Source: https://habr.com/ru/post/1312711/


All Articles