Regarding form_for and fields-for content variable

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?

On Jan 26, 9:20 am, byrnejb [email protected] wrote:

Now, while I know that ff != dependency

This should be association rather than dependency. What I am asking
is why, when ff acts in the place of a specific model.association, I
cannot reach model.association.dependency.attribute.

The problem domain requires that associations be created separately
from either the model or the dependency but must be associated to an
extant qualified row in each.

James B. wrote:

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’?

A FormBuilder. The documentation for form_for already tells you this.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

The most general it is a block value. For a from builder |f| is a
form object with association parameters that have attributes that
correspond to the object. f.text_field :name, :name is a db column
or an attribute of the class.

same as:
array.each do |val|
puts val
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs