Nested Attributes in a Form for Has_One Model Association in Rails

Just for reference…

class Member < ActiveRecord::Base
    has_one :member_profile
    accepts_nested_attributes_for :member_profile
end
<p>
<% form_for @member do |f| -%>
       <%= f.label :fullname %> <%= f.text_field :fullname %>
	<% f.fields_for :member_profile, @member.member_profile do |member_profile|%>
               <p><%= member_profile.label :about %><%= member_profile.text_field :about %></p>
               <p><%= member_profile.label :favorite_color %><%= member_profile.text_field :favorite_color %></p>
	<% end %>
</p>
  • http://www.scratch22.net zarne

    ahhh Just when I need to see the controller… :\ ;)

    • bseanvt

      That’s because there is nothing in the controller besides the variable assignment.

      MembersController < ApplicationController
      @member = Member.new
      end