<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Rails Forum - Ruby on Rails Help and Discussion Forum - Creating Variable Number of Models in One Form]]></title>
		<link>http://railsforum.com/viewtopic.php?id=1065</link>
		<description><![CDATA[The most recent posts in Creating Variable Number of Models in One Form.]]></description>
		<lastBuildDate>Fri, 27 Mar 2009 22:30:52 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Creating Variable Number of Models in One Form]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=91936#p91936</link>
			<description><![CDATA[<p>Thanks for this post - It almost got me there!</p><p>I&#039;ve tried to apply this example to my application without much luck. I&#039;d like to create a form with multiply records. The parent records are already created and now need to be able to add N number of child records from a single form (tabular format, 5 columns per row).</p><p>The examples show this processing through the parent (project) controller - how would this be approached if going through the child controller?</p><p>I&#039;m currently using rails 2.3.2</p><p>------------------- Thrown Exception --------------------------------------<br /> Showing app/views/timeslips/_newform.html.erb where line #16 raised:</p><p>undefined method `each_with_index&#039; for #&lt;Timeslip:0xb6e1619c&gt;</p><p>Extracted source (around line #16):</p><p>13:&nbsp; &nbsp;&lt;p&gt;<br />14:&nbsp; &nbsp;&lt;h2&gt;Timeslips&lt;/h2&gt;<br />15:&nbsp; &nbsp;&lt;div id=&quot;timeslips&quot;&gt;<br />16:&nbsp; &nbsp; &nbsp;&lt;% @timeslip.each_with_index do |timeslip, index| %&gt;<br />17:&nbsp; &nbsp; &nbsp; &nbsp;&lt;%= render :partial =&gt; &#039;timeslip_fields&#039;, :locals =&gt; { :timeslip =&gt; timeslip, :index =&gt; index } %&gt;<br />18:&nbsp; &nbsp; &nbsp;&lt;% end %&gt;<br />19:&nbsp; &nbsp;&lt;/div&gt;</p>]]></description>
			<author><![CDATA[dummy@example.com (rapia)]]></author>
			<pubDate>Fri, 27 Mar 2009 22:30:52 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=91936#p91936</guid>
		</item>
		<item>
			<title><![CDATA[Re: Creating Variable Number of Models in One Form]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=76580#p76580</link>
			<description><![CDATA[<p>Thanks for this post - I searched high and low for this information and only came across this tutorial after several days of Googling. And I was able to port this to work with jRails with very little modifications.</p>]]></description>
			<author><![CDATA[dummy@example.com (chrisbloom7)]]></author>
			<pubDate>Wed, 01 Oct 2008 01:02:33 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=76580#p76580</guid>
		</item>
		<item>
			<title><![CDATA[Re: Creating Variable Number of Models in One Form]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=71572#p71572</link>
			<description><![CDATA[<p>This is a great tutorial and thanks to a new gem, ActivePresenter, things are looking a lot easier for working with multiple models in a single form.</p><p><a href="http://jamesgolick.com/2008/7/28/introducing-activepresenter-the-presenter-library-you-already-know">http://jamesgolick.com/2008/7/28/introd &#133; ready-know</a></p><p>Lots of the logic and RJS that Ryan describes could easily be modified to work with ActivePresenter as well.&nbsp; It doesn&#039;t support building multiple child model records yet but that will soon be supported (which is a major point of this tutorial).&nbsp; But the promise is there.</p>]]></description>
			<author><![CDATA[dummy@example.com (MDWeezer)]]></author>
			<pubDate>Tue, 12 Aug 2008 13:24:09 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=71572#p71572</guid>
		</item>
		<item>
			<title><![CDATA[Re: Creating Variable Number of Models in One Form]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=71554#p71554</link>
			<description><![CDATA[<p>Yeah, if you need to reference it I would do it by hand.</p>]]></description>
			<author><![CDATA[dummy@example.com (emily)]]></author>
			<pubDate>Tue, 12 Aug 2008 10:33:05 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=71554#p71554</guid>
		</item>
		<item>
			<title><![CDATA[Re: Creating Variable Number of Models in One Form]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=69696#p69696</link>
			<description><![CDATA[<p>Hi Ryan,</p><p>Just wanted to extend a huge thank you. I&#039;m just beginning with rails and this tutorials you&#039;ve made about forms were just what I needed. Again, Thank You!</p>]]></description>
			<author><![CDATA[dummy@example.com (aficiomaquinas)]]></author>
			<pubDate>Sat, 26 Jul 2008 23:05:19 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=69696#p69696</guid>
		</item>
		<item>
			<title><![CDATA[Re: Creating Variable Number of Models in One Form]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=68312#p68312</link>
			<description><![CDATA[<p>This great article helped me a lot. What is the best way to show error messages for different tasks in case that validation fails? Obviously, &lt;%= error_messages_for &quot;tasks[#{index}]&quot; %&gt; isn&#039;t the correct way to handle the situation.</p>]]></description>
			<author><![CDATA[dummy@example.com (jukka)]]></author>
			<pubDate>Sun, 13 Jul 2008 20:27:35 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=68312#p68312</guid>
		</item>
		<item>
			<title><![CDATA[Re: Creating Variable Number of Models in One Form]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=67833#p67833</link>
			<description><![CDATA[<p>Hey All,</p><p>I am running into a strange problem where every time I edit two models in one form, and hit the Update button, I get the error :<br />No route matches &quot;/obligation/update&quot; with {:method=&gt;:post}</p><p>I have 2 models : obligation and assignment.</p><p>obligation has_many :assignments and assignment belongs_to :obligation</p><p>I have changed the update def code and modified the edit file but dont know why it is not working out.</p><p>Please help me out with it!</p>]]></description>
			<author><![CDATA[dummy@example.com (CrazyR)]]></author>
			<pubDate>Tue, 08 Jul 2008 23:14:04 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=67833#p67833</guid>
		</item>
		<item>
			<title><![CDATA[Re: Creating Variable Number of Models in One Form]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=61158#p61158</link>
			<description><![CDATA[<p>Hi Ryan, </p><p>Thanks for your tutorial(looks that made it to <a href="http://www.pragprog.com/titles/fr_arr/advanced-rails-recipes">Advanced Rails Recipe</a> ). I had a look at it and it&#039;s much more simpler than the original post.</p>]]></description>
			<author><![CDATA[dummy@example.com (fadhlirahim)]]></author>
			<pubDate>Thu, 01 May 2008 05:39:40 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=61158#p61158</guid>
		</item>
		<item>
			<title><![CDATA[Re: Creating Variable Number of Models in One Form]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=60169#p60169</link>
			<description><![CDATA[<p>haze: If you&#039;re using Rails 2.0, I don&#039;t think that the inplace editor is in the core anymore. I believe it&#039;s been moved into a plugin.</p>]]></description>
			<author><![CDATA[dummy@example.com (anlek)]]></author>
			<pubDate>Sat, 19 Apr 2008 03:56:52 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=60169#p60169</guid>
		</item>
		<item>
			<title><![CDATA[Re: Creating Variable Number of Models in One Form]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=59544#p59544</link>
			<description><![CDATA[<p>Thanks for a really good tutorial.</p><p>I have a small problem:<br />My &quot;tasks&quot; is added fine and it looks nice. But I want to use a in_place_editor_field inside my fields_for for every &quot;task&quot; but I get the error:</p><p>&quot;ActionView::TemplateError (undefined method `in_place_editor_for&#039; for #&lt;ActionView::Helpers::FormBuilder:0x244620c&gt;)&quot;</p><br /><p>Can I patch the ActionViewHelper in some way or is there a workaround or an other way?</p>]]></description>
			<author><![CDATA[dummy@example.com (haze)]]></author>
			<pubDate>Sat, 12 Apr 2008 09:16:11 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=59544#p59544</guid>
		</item>
		<item>
			<title><![CDATA[Re: Creating Variable Number of Models in One Form]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=58273#p58273</link>
			<description><![CDATA[<p>hi i&#039;m really a newbie in rails.<br />i&#039;m doing a project about online rostering.<br />if i have 2 tables (model) - person, work_shift<br />is this &quot;Creating Variable Number of Models in One Form&quot; method can be use to make this type of interface (see below):</p><p>#it will loop n person i have in table person.<br />#day will be entered manually using drop down/text field.</p><p>Person | shift_day <br />john&nbsp; &nbsp;| monday <br />doe&nbsp; &nbsp; | tuesday<br />dann&nbsp; &nbsp;| wednesday<br />rob&nbsp; &nbsp; | thursday<br />carl&nbsp; &nbsp;| friday</p><p>(save shift)</p><p>i want to know if i click (save shift) it will save that 5 new records in shift table.</p><p>by the way,<br />this is what in the table person: id, name<br />this is what in the table work_shift: person_id, shift_day</p><p>i tried this tutorial before in my other project. in 1 form, it will add 2 records. 1 record in user table and 1 record in student table. (work like a charm, thank you!)<br />e.g.<br />user - id = 1, name = john<br />student - id = 1, user_id = 1</p>]]></description>
			<author><![CDATA[dummy@example.com (brandy88)]]></author>
			<pubDate>Sat, 29 Mar 2008 14:01:20 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=58273#p58273</guid>
		</item>
		<item>
			<title><![CDATA[Re: Creating Variable Number of Models in One Form]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=56721#p56721</link>
			<description><![CDATA[<p>Hello Ryan, once again thanks for your great work.<br />I have a form where users can create a project and add several tasks following your railscast (complex forms part 1 and 2) and it works great but I need to know in the task form partial how many tasks are already created so I started looking on internet and in this forum and I found this tutorial that I guess works great but it uses a different approach so my question is: is it possible to add the add_task link the &quot;index&quot; with the code you show on the railscast instead in this tutorial ?</p><p>THANK YOU SO MUCH, I APPRECIATE YOUR HELP</p>]]></description>
			<author><![CDATA[dummy@example.com (macsig)]]></author>
			<pubDate>Tue, 11 Mar 2008 01:04:05 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=56721#p56721</guid>
		</item>
		<item>
			<title><![CDATA[Re: Creating Variable Number of Models in One Form]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=56339#p56339</link>
			<description><![CDATA[<p>OK, so I&#039;ve got a nice nested hash using this string for the fields_for first parameter...</p><p><pre name="code" class="ruby:nogutter"> &lt;% fields_for &quot;lessons_edited[#{lesson}][assignments][#{index}]&quot;, assignment do |assignment_form| %&gt;</p><p>...stuff here...<br />&lt;% end %&gt;</pre><br />That gives me the hash organization that I need.</p><p>Now my problem...</p><p>The assignment form consists of dynamic drop-downs updated with observe_field. So, the final partial which is used to select the &#039;segment_id&#039; for the assignment isn&#039;t working as I would expect/hope. The &#039;assignment_form&#039; method from the form builder block doesn&#039;t seem to like my select control... neither collection_select nor select. When I use...</p><p><pre name="code" class="ruby:nogutter"> assignment_form.text_field :segment_id</pre><br />I can manually type in a value and get back the hash I need.</p><p>When I use...<br /><pre name="code" class="ruby:nogutter"> assignment_form.select :segment_id, @segments.collect {|s| [s.id, s.full_name]}</pre><br />I get...<br /><pre name="code" class="ruby:nogutter">ActionView::TemplateError (wrong number of arguments (3 for 0)) on line #3 of app/views/lessons/_segments.rhtml:<br />...<br />3: &lt;%= assignment_form.select :segment_id, @segments.collect {|s| [s.id, s.full_name]}, {} %&gt;</pre><br />When I use...<br /><pre name="code" class="ruby:nogutter">assignment_form.collection_select :segment_id, @segments, :id, :full_name</pre><br />I get...<br /><pre name="code" class="ruby:nogutter">ActionView::TemplateError (undefined method `collection_select&#039; for &quot;#&lt;ActionView::Helpers::FormBuilder:0x3461d80&gt;&quot;:String) on line #3 of app/views/lessons/_segments.rhtml:<br />...<br />3: &lt;%= assignment_form.collection_select :segment_id, @segments, :id, :full_name %&gt;</pre><br />Any help would be appreciated.</p>]]></description>
			<author><![CDATA[dummy@example.com (ricsrock)]]></author>
			<pubDate>Wed, 05 Mar 2008 22:45:13 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=56339#p56339</guid>
		</item>
		<item>
			<title><![CDATA[Re: Creating Variable Number of Models in One Form]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=55319#p55319</link>
			<description><![CDATA[<p>Working from this basic scenario, how would I go about adding a nested fields_for element?</p><p>I have a form which edits many instances of a &quot;lesson&quot; model and (hopefully) will add any number of &quot;assignments&quot; to any lesson.</p><p><pre name="code" class="ruby:nogutter">&lt;% form_remote_tag :url =&gt; {:action =&gt; &#039;update_assignments&#039;, :student =&gt; @student, :week =&gt; @set_week} do |f| %&gt;</p><br /><p>&lt;% for lesson in lessons_day_subject %&gt;<br />&nbsp; &lt;% fields_for &quot;lessons[#{lesson.id}]&quot;, lesson do |f| %&gt;<br />&nbsp; ...lesson fields here...&nbsp; &nbsp; <br />&nbsp; &lt;% lesson.assignments.each_with_index do |assignment, index| %&gt;<br />&nbsp; &nbsp; &lt;%= render :partial =&gt; &#039;assignment_fields&#039;, :locals =&gt; { :assignment =&gt; assignment, :index =&gt; index, :subject =&gt; @subject.id, :lesson =&gt; lesson } %&gt;<br />&nbsp; &nbsp; &lt;% end %&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&lt;%= submit_tag &#039;Save All&#039; %&gt;<br />&lt;% end %&gt;</p><p>#assignment_fields partial...<br />#this is what I don&#039;t get!<br />&lt;% fields_for &quot;assignments[#{index}]&quot; do |assignment| %&gt;<br />&nbsp; ...assignment fields here...<br />&lt;% end %&gt;</pre><br />I&#039;m thinking there should be a way to get things arranged in a nested hash back to the controller, something like...<br /><pre name="code" class="ruby:nogutter">&quot;<br />&quot;lessons&quot;=&gt;{&quot;172&quot;=&gt;{&quot;comments&quot;=&gt;&quot;comments here&quot;, &quot;assignments&quot;=&gt; {&quot;0&quot;=&gt; {&quot;lesson_id&quot; =&gt; &quot;213&quot;, &quot;segment_id&quot;=&gt;&quot;78&quot;}, {&quot;1&quot; =&gt; {&quot;lesson_id&quot;=&gt;&quot;214&quot;, &quot;segment_id&quot;=&gt;&quot;79&quot;}}}...</pre><br />...but to no avail so far.</p><p>Your help is appreciated.</p>]]></description>
			<author><![CDATA[dummy@example.com (ricsrock)]]></author>
			<pubDate>Mon, 25 Feb 2008 22:40:35 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=55319#p55319</guid>
		</item>
		<item>
			<title><![CDATA[Re: Creating Variable Number of Models in One Form]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=52607#p52607</link>
			<description><![CDATA[<p>First off, thanks for a fantastic tutorial. I can&#039;t believe I blew an hour trying to figure out a problem with the controller.</p><p>Using Rails 2.0. When adding another &quot;task&quot;, nothing happened and I kept getting the following in development.log:<br />ActionController::MissingTemplate (Missing template people/add_address.html.erb in view path /home/Scott/track/app/views):</p><p>Turns out I didn&#039;t notice I need a respond_to in the controller for add_task</p><p><pre name="code" class="ruby:nogutter"># in projects_controller.rb<br />def add_task<br />&nbsp; @task = Task.new<br />&nbsp; <br />&nbsp; respond_to do |format|<br />&nbsp; &nbsp; format.js<br />&nbsp; end&nbsp; <br />end</pre><br />Hope this helps someone.</p>]]></description>
			<author><![CDATA[dummy@example.com (fivedobies)]]></author>
			<pubDate>Fri, 01 Feb 2008 00:15:28 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=52607#p52607</guid>
		</item>
	</channel>
</rss>
