# Forms filled at initialization?

**URL:** <https://www.ruby-forum.com/t/forms-filled-at-initialization/105182>\
**Category:** Rails\
**Created:** [May 26, 2007, 9:13pm UTC](https://www.ruby-forum.com/t/forms-filled-at-initialization/105182 "2007-05-26T21:13:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hpacheco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/dfb087/32.png) [@hpacheco](https://www.ruby-forum.com/u/hpacheco)\
**Post date:** [May 26, 2007, 9:13pm UTC](https://www.ruby-forum.com/t/forms-filled-at-initialization/105182/1 "2007-05-26T21:13:35Z")

</div>

Hi,

I’ve created some a form for filling some signup information for an  
user.

Now i need to reuse the same code to create an ‘edit information’  
form, what means that the forms needs to be initialized with the  
values stored in the database.

I suppose there is some automatic mean of doing such, but can’t find  
no information on this topic.

Thanks in advance,  
hugo

---

<div class="post-metadata">

**Author:** ![hpacheco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/dfb087/32.png) [@hpacheco](https://www.ruby-forum.com/u/hpacheco)\
**Post date:** [May 26, 2007, 9:42pm UTC](https://www.ruby-forum.com/t/forms-filled-at-initialization/105182/2 "2007-05-26T21:42:02Z")

</div>

hpacheco wrote:

> Hi,
> 
> I’ve created some a form for filling some signup information for an  
> user.
> 
> Now i need to reuse the same code to create an ‘edit information’  
> form, what means that the forms needs to be initialized with the  
> values stored in the database.
> 
> I suppose there is some automatic mean of doing such, but can’t find  
> no information on this topic.
> 
> Thanks in advance,  
> hugo

Try to look at scaffold, they do that and you can learn from it 🙂

---

<div class="post-metadata">

**Author:** ![hpacheco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/dfb087/32.png) [@hpacheco](https://www.ruby-forum.com/u/hpacheco)\
**Post date:** [May 27, 2007, 10:06am UTC](https://www.ruby-forum.com/t/forms-filled-at-initialization/105182/3 "2007-05-27T10:06:38Z")

</div>

On 5/26/07, hpacheco [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I suppose there is some automatic mean of doing such, but can’t find  
> no information on this topic.
> 
> Thanks in advance,  
> hugo

There are 2 basic types of form helpers: the form helpers and the form  
tag helpers. The form tag helpers are basic wrappers around input  
tags.

\<%= text\_field\_tag :search, params[:search] %\>

Form helpers work with objects:

\<%= text\_field ‘user’, ‘name’ %\>

This will prefill with the value from @user.name, and set a form name  
of “user[name]”. form\_for gives you a nice shortcut for this:

\<% form\_for :user do |form| -%\>  
\<%= form.text\_field :name %\>  
\<%= form.text\_field :email %\>  
\<% end -%\>

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)
