I am trying to understand what I am working with when I deal with
Rails forms_for and fields_for constructors.
Given model has_many associations belongs_to dependency and
dependency has_many associations belongs_to model
@model = Model.find(:id)
and
forms_for @model do |f|
what is ‘f’?
f.fields_for :associations do |ff|
what is ‘ff’?
How do I access dependencies on the named associations?
I have inspected these things and the volume of data that each
contains is such that I cannot post it here. My difficulty is that I
cannot seem to get a handled
I will try to give an example:
forms_for @model do |f|
f.fields-for :associations do |ff|
ff.text-field :model_id
ff.text_field :dependency_id:
ff.dependency.some_attribute # this display value simply does not
work.
ff.collection_select(
:dependency_id, @dependencies, :id, :name,
{ :prompt => ‘Select a name’ }, #options hash
{ :class => :input_select, #html hash
:id => :input_name,
:size => 1,
:title => I18n.t(‘Enter a valid name’),
:value => ff.dependency_id } # this does not
work either
)
Now, while I know that ff != dependency it does seem to me counter
intuitive that for each association of model I am unable to directly
address the dependency attributes from within the form constructor.
What is my fundamental misunderstanding with respect to forms_for and
fields_for and their treatment of DBMS rows? How does one obtain a
dependent attribute for display purposes within a forms_for or
fields_for construct?