<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sean&#039;s Blog &#187; has_one</title>
	<atom:link href="http://seanbehan.com/tag/has_one/feed/" rel="self" type="application/rss+xml" />
	<link>http://seanbehan.com</link>
	<description>Web Programming, Ruby on Rails, Wordpress, PHP from Burlington, Vermont</description>
	<lastBuildDate>Tue, 31 Aug 2010 14:38:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Nested Has_one Relationship with Fields_for and Attr_accessible in Model Class</title>
		<link>http://seanbehan.com/ruby-on-rails/nested-has_one-relationship-with-fields_for-and-attr_accessible-in-model-class/</link>
		<comments>http://seanbehan.com/ruby-on-rails/nested-has_one-relationship-with-fields_for-and-attr_accessible-in-model-class/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 01:21:27 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[attr_accessible]]></category>
		<category><![CDATA[has_one]]></category>
		<category><![CDATA[nested forms]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=457</guid>
		<description><![CDATA[To make child attributes accessible to your model through a nested forms (Rails 2.3) you'll need to add the "#{child_class}_attributes" to the attr_accessible method in your parent class. If you don't use attr_accessible in your parent model (you would do this to restrict certain attributes to be accessed via a web form) then you should be all set.]]></description>
			<content:encoded><![CDATA[<p>To make child attributes accessible to your model through a nested forms (Rails 2.3) you&#8217;ll need to add the &#8220;#{child_class}_attributes&#8221; to the attr_accessible method in your parent class. If you don&#8217;t use attr_accessible in your parent model (you would do this to restrict certain attributes to be accessed via a web form) then you should be all set.</p>
<p>Below is an example where User has_one Profile with the favorite_color attribute being set/updated in the nested form.</p>
<pre>
class User < ActiveRecord::Base
  has_one :profile #child class
  accepts_nested_attributes_for :profile
  attr_accessible :profile_attributes # the format is the child_class followed by the "_attributes"
end
</pre>
<p>And the form would like this...</p>
<pre>
<% form_for @current_user do |f| %>
   <% f.fields_for :profile do |profile| %>
     <%= profile.text_field :favorite_color %>
  <% end %>
<% end %>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/ruby-on-rails/nested-has_one-relationship-with-fields_for-and-attr_accessible-in-model-class/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Nested Attributes in a Form for Has_One Model Association in Rails</title>
		<link>http://seanbehan.com/ruby-on-rails/nested-attributes-in-a-form-for-has_one-model-association-in-rails/</link>
		<comments>http://seanbehan.com/ruby-on-rails/nested-attributes-in-a-form-for-has_one-model-association-in-rails/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 17:13:50 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[has_one]]></category>
		<category><![CDATA[nested]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=449</guid>
		<description><![CDATA[Just for reference&#8230; class Member < ActiveRecord::Base has_one :member_profile accepts_nested_attributes_for :member_profile end]]></description>
			<content:encoded><![CDATA[<p>Just for reference&#8230;</p>
<pre>
class Member < ActiveRecord::Base
    has_one :member_profile
    accepts_nested_attributes_for :member_profile
end
</pre>
<pre>


<% form_for @member do |f| -%>
       <%= f.label :fullname %> <%= f.text_field :fullname %>
	<% f.fields_for :member_profile, @member.member_profile do |member_profile|%>

<%= member_profile.label :about %><%= member_profile.text_field :about %>

<%= member_profile.label :favorite_color %><%= member_profile.text_field :favorite_color %>

	<% end %>

</pre>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/ruby-on-rails/nested-attributes-in-a-form-for-has_one-model-association-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
