Formatting form fields of a nested model (Rails 3)

So here is the scenario:

User:

has_one :company
accepts_nested_attributes_for :company

Controller:

@user = User.new
@user.build_company

View:

<% semantic_form_for @user, :url => register_path do |form| %>

  <h2>User Information</h2>

  <%= form.inputs %>

  <h2>Company Information</h2>

  <% form.semantic_fields_for :company do |company| %>
    <%= company.inputs %>
  <% end %>

  <%= form.buttons %>

<% end %>

After cleaning the web pages, this is SEEMS, as it should work. However, all I get is user inputs. The semantic_fields_for: company block does not display anything ...

Am I missing something, or is it possibly a Rails 3 error with Formtastic?

+5
source share
2 answers

You need to use "<% =%>" with Rails 3 blocks instead of "<%%>" . Thus, the code should be:

<%= semantic_form_for @user, :url => register_path do |form| %>

  <h2>User Information</h2>

  <%= form.inputs %>

  <h2>Company Information</h2>

  <%= form.semantic_fields_for :company do |company| %>
    <%= company.inputs %>
  <% end %>

  <%= form.buttons %>

<% end %>
+4
source

rails3,

@user.company.build

@user.build_company

+1

All Articles