问题描述:

Alright, I've got to be doing something stupid here because my code has been pared to the bare minimum example and its still not working.

Here's the deal:

user.rb

...

attr_accessible :username, :retail_profile_attributes

...

belongs_to :retail_profile

accepts_nested_attributes_for :retail_profile

...

*retail_profile.rb*

attr_accessible :company_name

belongs_to :user

*registrations_controller.rb*

def new

@user = User.new

@user.build_retail_profile

end

new.html.erb

<%= form_for resource, :as => resource_name, :url => registration_path(resource_name) do |f| %>

<p><%= f.label :username %><br />

<%= f.text_field :username %></p>

<%= f.fields_for :retail_profile do |builder| %>

<p><%= builder.label :company_name %><br />

<%= builder.text_field :company_name %></p>

<% end %>

<p><%= f.submit "Submit" %></p>

<% end %>

So what happens is that the form that renders shows the username field, but fails to show the company_name field. If i put a debug statement in on @user.retail_profile.nil? it always comes back true, so apparently my statement in the registrations_controller -- @user.build_retail_profile -- isnt actually doing anything.

I've seen examples that look just like this all over the place, so I must be doing something remarkably stupid here I just can't figure out what it is.

Help?

相关阅读:
Top