# My form\_for example works correctly, but \*WHY\* does it work?

**URL:** <https://www.ruby-forum.com/t/my-form-for-example-works-correctly-but-why-does-it-work/108257>\
**Category:** Rails\
**Created:** [July 1, 2007, 4:35am UTC](https://www.ruby-forum.com/t/my-form-for-example-works-correctly-but-why-does-it-work/108257 "2007-07-01T04:35:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/838e76/32.png) [@rob](https://www.ruby-forum.com/u/rob)\
**Post date:** [July 1, 2007, 4:35am UTC](https://www.ruby-forum.com/t/my-form-for-example-works-correctly-but-why-does-it-work/108257/1 "2007-07-01T04:35:38Z")

</div>

Hello,

I am still new to Rails and have been trying to understand forms and  
form\_for, but it seems there are a number of ways to do / specify  
things that all work fine. For example, I created this simple example  
that works exactly how it should:

[http://pastie.caboo.se/75110](http://pastie.caboo.se/75110)

My questions are:

- I see many people do \<% form\_for :category, @category … %\>,  
whereas I did just \<% form\_for :category … %\>. Someone said this  
would be so the @category instance variable would be available to  
prepopulate the form on validation, but my example successfully  
prepopulates the form just fine on validation without the addition of  
@category. Why?

- Doing :object =\> f causes us to use the ‘form’ object when  
specifying methods like form.text\_field. Where did ‘form’ come from? I  
noticed I can achieve the same thing doing :locals =\> { :f =\> f } and  
then using f.text\_field in the helper.

Thanks for the help in understanding this.

---

<div class="post-metadata">

**Author:** ![rob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/838e76/32.png) [@rob](https://www.ruby-forum.com/u/rob)\
**Post date:** [July 1, 2007, 11:15am UTC](https://www.ruby-forum.com/t/my-form-for-example-works-correctly-but-why-does-it-work/108257/2 "2007-07-01T11:15:00Z")

</div>

Some Browsers (e.g. FF) Save form data when you go back&forth in  
browser history. Taht may be it. Test it in IE and i my guess is that  
it won’t work there 😉

rob schrieb:
