Using fields from an association (has_one) model with formtastic in rails

Posted by subprime on Stack Overflow See other posts from Stack Overflow or by subprime
Published on 2010-03-26T21:46:21Z Indexed on 2010/04/12 8:43 UTC
Read the original article Hit count: 626

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!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about formtastic