# ActionView::Helpers::FormHelper instance methods should take

**URL:** <https://www.ruby-forum.com/t/actionview-formhelper-instance-methods-should-take/57248>\
**Category:** Rails\
**Created:** [April 8, 2006, 5:53pm UTC](https://www.ruby-forum.com/t/actionview-formhelper-instance-methods-should-take/57248 "2006-04-08T17:53:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a4c791/32.png) [@alder](https://www.ruby-forum.com/u/alder)\
**Post date:** [April 8, 2006, 5:53pm UTC](https://www.ruby-forum.com/t/actionview-formhelper-instance-methods-should-take/57248/1 "2006-04-08T17:53:25Z")

</div>

Hi

ActionView::Helpers::FormHelper methods (e.g. #text\_field,  
#check\_box…) take object\_name as an argument. From this argument  
they infer a name that is supposed to contains the reference to the  
relevant object.

I can’t see why the FormHelper methods were designed that way.  
Compared to simply passing them a reference, the current way seems too  
complicated and an invitation to problems or at least limitations.

For example, if you call text\_field(“post”, “title”), the method would  
look for a @post instance variable. Imagine you were using a local  
variable for storing the relevant object, instead of an instance  
variable. If text\_field took a reference, you would just call it with  
text\_field(post, :title). However, since it takes a string an infers a  
reference name, you now have to change your assigned names or at least  
create new aliases to your existing names.

To sum up, I can’t see any advantages to the object\_name approach, I  
don’t understand why FormHelper was initially designed that way, so I  
think it should be changed so as to be more convenient and flexible.  
What do you think?

Regards,  
Alder

---

<div class="post-metadata">

**Author:** ![alder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a4c791/32.png) [@alder](https://www.ruby-forum.com/u/alder)\
**Post date:** [April 8, 2006, 5:56pm UTC](https://www.ruby-forum.com/t/actionview-formhelper-instance-methods-should-take/57248/2 "2006-04-08T17:56:34Z")

</div>

On Saturday 08 April 2006 17:50, Alder G. wrote:

> think it should be changed so as to be more convenient and flexible.  
> What do you think?
> 
> Regards,  
> Alder

It provides some useful additions. Like mass assigning with  
.attributes=, and  
the use of validations without worrying about anything. Look at my post  
on the  
list I made 2 minutes before you did, which explains a bit about  
validations.

In situations where you encounter limitations, use the text\_field\_tag  
method  
instead.

---

<div class="post-metadata">

**Author:** ![alder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a4c791/32.png) [@alder](https://www.ruby-forum.com/u/alder)\
**Post date:** [April 8, 2006, 6:02pm UTC](https://www.ruby-forum.com/t/actionview-formhelper-instance-methods-should-take/57248/3 "2006-04-08T18:02:59Z")

</div>

\<…\>

> For example, if you call text\_field(“post”, “title”), the method would  
> look for a @post instance variable. Imagine you were using a local  
> variable for storing the relevant object, instead of an instance  
> variable. If text\_field took a reference, you would just call it with  
> text\_field(post, :title). However, since it takes a string an infers a  
> reference name, you now have to change your assigned names or at least  
> create new aliases to your existing names.  
> \<…\>

… or simply use text\_field\_tag instead of text\_field.

> To sum up, I can’t see any advantages to the object\_name approach, I  
> don’t understand why FormHelper was initially designed that way, so I  
> think it should be changed so as to be more convenient and flexible.  
> What do you think?

Nothing should be changed, When you want to work with model’s  
attributes you use text\_field (which makes updates as simple as  
update\_attributes params[:model]) ,  
when you want something ‘flexible’ you use text\_field\_tag.

## Regards, Rimantas

[http://rimantas.com/](http://rimantas.com/)
