<?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>Wed, 18 Jan 2012 21:44:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.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[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fruby-on-rails%2Fnested-has_one-relationship-with-fields_for-and-attr_accessible-in-model-class%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Nested Has_one Relationship with Fields_for and Attr_accessible in Model Class" data-url="http://seanbehan.com/ruby-on-rails/nested-has_one-relationship-with-fields_for-and-attr_accessible-in-model-class/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><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="wp-code-highlight prettyprint">
class User &lt; 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 &quot;_attributes&quot;
end
</pre>
<p>And the form would like this&#8230;</p>
<pre class="wp-code-highlight prettyprint">
&lt;% form_for @current_user do |f| %&gt;
   &lt;% f.fields_for :profile do |profile| %&gt;
     &lt;%= profile.text_field :favorite_color %&gt;
  &lt;% end %&gt;
&lt;% end %&gt;
</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>14</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 &#60; ActiveRecord::Base has_one :member_profile accepts_nested_attributes_for :member_profile end &#60;p&#62; &#60;% form_for @member do &#124;f&#124; -%&#62; &#60;%= f.label :fullname %&#62; &#60;%= f.text_field :fullname %&#62; &#60;% f.fields_for :member_profile, @member.member_profile do &#124;member_profile&#124;%&#62; &#60;p&#62;&#60;%= member_profile.label :about %&#62;&#60;%= member_profile.text_field :about %&#62;&#60;/p&#62; &#60;p&#62;&#60;%= member_profile.label :favorite_color %&#62;&#60;%= member_profile.text_field :favorite_color %&#62;&#60;/p&#62; &#60;% end %&#62; &#60;/p&#62;]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fruby-on-rails%2Fnested-attributes-in-a-form-for-has_one-model-association-in-rails%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Nested Attributes in a Form for Has_One Model Association in Rails" data-url="http://seanbehan.com/ruby-on-rails/nested-attributes-in-a-form-for-has_one-model-association-in-rails/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>Just for reference&#8230;</p>
<pre class="wp-code-highlight prettyprint">
class Member &lt; ActiveRecord::Base
    has_one :member_profile
    accepts_nested_attributes_for :member_profile
end
</pre>
<pre class="wp-code-highlight prettyprint">
&lt;p&gt;
&lt;% form_for @member do |f| -%&gt;
       &lt;%= f.label :fullname %&gt; &lt;%= f.text_field :fullname %&gt;
	&lt;% f.fields_for :member_profile, @member.member_profile do |member_profile|%&gt;
               &lt;p&gt;&lt;%= member_profile.label :about %&gt;&lt;%= member_profile.text_field :about %&gt;&lt;/p&gt;
               &lt;p&gt;&lt;%= member_profile.label :favorite_color %&gt;&lt;%= member_profile.text_field :favorite_color %&gt;&lt;/p&gt;
	&lt;% end %&gt;
&lt;/p&gt;
</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>2</slash:comments>
		</item>
	</channel>
</rss>

