views:

331

answers:

1

I searched and tried a lot, but I can't accomplish it as I want.. so here's my problem.

My models are:

class User < ActiveRecord::Base
  has_one :profile
  accepts_nested_attributes_for :profile
end

class Profile < ActiveRecord::Base
  attr_accessible :user_id, :form, :title, :name, :surname, :street, :housenumber, :zipcode, :place, :phone, :mobile, :fax, :url 
  belongs_to :user
end

In my view:

<% semantic_form_for @user do |form| %>
  <%= form.inputs :login, :email, :password%>
  <% form.semantic_fields_for :profile do |profile| %>
    <%= profile.inputs %>
  <% end %>
  <%= form.buttons %>  
<% end %>

My problem is that when I edit a person then it shows me the data on the profile. I would, that the fields from the profile even when creating a user are displayed.

Thanks a lot!

+1  A: 

You should add in your view before your form.semantic_fields_for:

<% @user.build_profile unless @user.profile %>

You could do it as well in your controller new after that you create your User object.

VP