<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Rails Forum - Ruby on Rails Help and Discussion Forum - associations problem on]]></title>
		<link>http://railsforum.com/viewtopic.php?id=52287</link>
		<description><![CDATA[The most recent posts in associations problem on.]]></description>
		<lastBuildDate>Fri, 01 Feb 2013 23:35:21 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[associations problem on]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=158748#p158748</link>
			<description><![CDATA[<p>I can&#039;t figure out how to do this. Using the appointments example here (2.4) <a href="http://guides.rubyonrails.org/association_basics.html">http://guides.rubyonrails.org/association_basics.html</a></p><p>How would I set up the new view for appointments? I&#039;m stuck on the routing problem as well. Let&#039;s say in this example that it&#039;s an app for doctors offices. So patients and physicians belong_to office.</p><p>My routes say </p><p>resources :office do<br />&nbsp; &nbsp; resources :patients<br />&nbsp; &nbsp; resources :physicians<br />&nbsp; &nbsp; resources :appointments<br />end</p><p>I thought I could do domain.com/offices/id/appointments/new</p><p>Then on the new view</p><br /><p>&nbsp; &nbsp; &lt;%= simple_form_for :appointments do |u| %&gt;</p><p>&nbsp; &nbsp; &lt;%= u.association :physicians, :as =&gt; :radio %&gt;<br />&nbsp; &nbsp; &lt;%= u.association :patients, :as =&gt; :radio %&gt;</p><p>&nbsp; &nbsp; &lt;%= u.input :app_date %&gt;<br />&nbsp; &nbsp; &lt;%= u.input :app_description %&gt;</p><p>&nbsp; &nbsp; &lt;%= u.button :submit %&gt;<br />&nbsp; &nbsp; &lt;% end %&gt;</p><br /><p>I get &quot;Association cannot be used in forms not associated with an object&quot; error</p><br /><p>My appointments controller </p><p>&nbsp; def new<br />&nbsp; &nbsp; @office = current_user.offices.find_by_id(params[:office_id])<br />&nbsp; &nbsp; @patients = @office.patients<br />&nbsp; &nbsp; @physicians = @office.physicians<br />&nbsp; &nbsp; @appointments = @office.appointments.build<br />&nbsp; end</p>]]></description>
			<author><![CDATA[dummy@example.com (71)]]></author>
			<pubDate>Fri, 01 Feb 2013 23:35:21 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=158748#p158748</guid>
		</item>
	</channel>
</rss>
