# Regarding form\_for and fields-for content variable

**URL:** <https://www.ruby-forum.com/t/regarding-form-for-and-fields-for-content-variable/182317>\
**Category:** Rails\
**Created:** [January 26, 2010, 3:21pm UTC](https://www.ruby-forum.com/t/regarding-form-for-and-fields-for-content-variable/182317 "2010-01-26T15:21:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [January 26, 2010, 3:21pm UTC](https://www.ruby-forum.com/t/regarding-form-for-and-fields-for-content-variable/182317/1 "2010-01-26T15:21:57Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [January 26, 2010, 3:32pm UTC](https://www.ruby-forum.com/t/regarding-form-for-and-fields-for-content-variable/182317/2 "2010-01-26T15:32:29Z")

</div>

On Jan 26, 9:20 am, byrnejb [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [January 26, 2010, 6:42pm UTC](https://www.ruby-forum.com/t/regarding-form-for-and-fields-for-content-variable/182317/3 "2010-01-26T18:42:27Z")

</div>

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](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [January 26, 2010, 10:41pm UTC](https://www.ruby-forum.com/t/regarding-form-for-and-fields-for-content-variable/182317/4 "2010-01-26T22:41:07Z")

</div>

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
