Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First off, as suggested by @nash, you should remove <code>@profile = @user.create_profile(params[:profile])</code> from your <code>create</code> action. <code>accepts_nested_attributes_for</code> will automatically create your profile for you.</p> <p>Check that your view is set up correctly for nested attributes. Should shouldn't be seeing anything in <code>params[:profile]</code>. The profile attributes need to come through in <code>params[:user][:profile_attributes]</code> for nested models to work correctly.</p> <p>In summary, your <code>create</code> action should look like this:</p> <pre><code>def create @user = User.new(params[:user]) if @user.save redirect_to root_url, :notice =&gt; "user created successfully!" else render "new" end end </code></pre> <p>Your form view (typically <code>_form.html.erb</code>) should look something like this:</p> <pre><code>&lt;%= form_for @user do |f| %&gt; Email: &lt;%= f.text_field :email %&gt; Password: &lt;%= f.password_field :password %&gt; &lt;%= f.fields_for :profile do |profile_fields| %&gt; Bio: &lt;%= profile_fields.text_field :bio %&gt; Birthday: &lt;%= profile_fields.date_select :birthday %&gt; Color: &lt;%= profile_fields.text_field :color %&gt; &lt;% end %&gt; &lt;%= f.submit "Save" %&gt; &lt;% end %&gt; </code></pre> <p>For more information, <a href="http://archives.ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes" rel="nofollow">see this old but great tutorial by Ryan Daigle</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload