I'm struggling with Rails syntax. I'm trying to set up a one-to-many relationship for users to addresses, but the user will always have a primary address. I've managed to get the model working, but I can'seem to get the form working. The form below is for "new registration", but the fields for the nested address don't show up.
I've been hacking away at this, and can't seem to get it. Could someone please explain why the nested form fields wouldn't show up when trying to register a New user?
This is the form
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => {:class => "form-horizontal"}) do |f| %>
<small>Mandatory fields marked *</small><br><br>
<%= f.fields_for :primary_address do |address_form| %>
<div class="control-group">
<%= address_form.label :first_name, :class => "control-label" %>
<div class="controls">
<%= address_form.text_field :first_name, :class => "input-xlarge" %>
</div>
</div>
<div class="control-group">
<%= address_form.label :last_name, :class => "control-label" %>
<div class="controls">
<%= address_form.text_field :last_name, :class => "input-xlarge" %>
</div>
</div>
<% end %>
This is the user model:
class Member::User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :addresses_attributes
validates_presence_of :email
# each user may have zero or many addresses
# their primary email is also set as their login id.
has_many :addresses
has_one :primary_address, :class_name => "Address", :conditions => "is_primary = true"
accepts_nested_attributes_for :primary_address
end
<% end %>on the bottom of the form?