Brian
Brian

Reputation: 6071

RoR field set on form_for

How do you add a field set to a form_for method?

Upvotes: 3

Views: 4211

Answers (2)

theTRON
theTRON

Reputation: 9649

You can use field_set_tag. For example, using a generic 'user' object

For Rails 2.3.x

<% form_for(@user) do |f| %>

  <% field_set_tag 'Name' do %>
    <%= f.text_field :first_name %>
    <%= f.text_field :last_name %>
  <% end %>

<% end %>

And for Rails 3.0.0:

<%= form_for(@user) do |f| %>

  <%= field_set_tag 'Name' do %>
    <%= f.text_field :first_name %>
    <%= f.text_field :last_name %>
  <% end %>

<% end %>

Upvotes: 3

Sam 山
Sam 山

Reputation: 42865

You need to have a new object or get an existing object from your dc since it is a 'form for' and then you create a form builder f and call methods on that form builder such as the following:

<% form_for(@object) do |f| %>
 <%= f.text_field :method_name %>
<% end %>

Upvotes: -1

Related Questions