Forms filled at initialization?

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

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 :slight_smile:

On 5/26/07, hpacheco [email protected] 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://weblog.techno-weenie.net
http://mephistoblog.com

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