<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Ruby on Rails &#8211; Insert Multiple Child Records</title>
	<atom:link href="http://og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/feed/" rel="self" type="application/rss+xml" />
	<link>http://og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/</link>
	<description>Leaders in Open Source</description>
	<lastBuildDate>Fri, 11 Jan 2008 06:31:18 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: shridevi</title>
		<link>http://og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/comment-page-1/#comment-52</link>
		<dc:creator>shridevi</dc:creator>
		<pubDate>Fri, 11 Jan 2008 06:31:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/#comment-52</guid>
		<description>Thanks for explaining the difference between check_box and check_box_tag my part of my problem got solved,but when I am checking more than one box  only one id is getting saved in the join table.Please help me hres the code I am trying

html





controller
 params[:o].collect do &#124;os_id&#124;

      @complist=CompanyListingsOperatingSystems.new(:company_listing_id=&gt;@a,:operating_system_id=&gt;os_id) if os_id != nil
      @complist.save</description>
		<content:encoded><![CDATA[<p>Thanks for explaining the difference between check_box and check_box_tag my part of my problem got solved,but when I am checking more than one box  only one id is getting saved in the join table.Please help me hres the code I am trying</p>
<p>html</p>
<p>controller<br />
 params[:o].collect do |os_id|</p>
<p>      @complist=CompanyListingsOperatingSystems.new(:company_listing_id=&gt;@a,:operating_system_id=&gt;os_id) if os_id != nil<br />
      @complist.save</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: O'Malley</title>
		<link>http://og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/comment-page-1/#comment-51</link>
		<dc:creator>O'Malley</dc:creator>
		<pubDate>Mon, 26 Nov 2007 14:59:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/#comment-51</guid>
		<description>­­The relevant portion of the code is this line above:

&lt;code&gt;@invoice.invoice_items &lt; &lt; InvoiceItem.new(:item_id =&gt; item_id)&lt;/code&gt;

From http://corelib.rubyonrails.org/classes/Array.html#M000405 :


  &lt;blockquote&gt;
Append—Pushes the given object on to the end of this array. This expression returns the array itself, so several appends may be chained together.
&lt;/blockquote&gt;

The &quot;&lt;&lt;&quot; is the aggregate method which allows you to append multiple rows to your invoice.invoice_items object.

This little bit I wrote is probably out of date, so your mileage may vary.  I&#039;d check a more definitive source at one of the ruby on rails community sites or http://api.rubyonrails.com/­</description>
		<content:encoded><![CDATA[<p>­­The relevant portion of the code is this line above:</p>
<p><code>@invoice.invoice_items &lt; &lt; InvoiceItem.new(:item_id =&gt; item_id)</code></p>
<p>From <a href="http://corelib.rubyonrails.org/classes/Array.html#M000405" rel="nofollow">http://corelib.rubyonrails.org/classes/Array.html#M000405</a> :</p>
<blockquote><p>
Append—Pushes the given object on to the end of this array. This expression returns the array itself, so several appends may be chained together.
</p></blockquote>
<p>The &quot;&lt;&lt;&quot; is the aggregate method which allows you to append multiple rows to your invoice.invoice_items object.</p>
<p>This little bit I wrote is probably out of date, so your mileage may vary.  I&#8217;d check a more definitive source at one of the ruby on rails community sites or <a href="http://api.rubyonrails.com/­" rel="nofollow">http://api.rubyonrails.com/­</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rohit</title>
		<link>http://og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/comment-page-1/#comment-50</link>
		<dc:creator>Rohit</dc:creator>
		<pubDate>Mon, 26 Nov 2007 14:17:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/#comment-50</guid>
		<description>Hi,

I want to insert multiple rows at once in the database. My functionality is to add product prices against different quantities. I have a table named productprices in the database. Now I require to insert product_id, quantity and price in the table as number of times as there are quantities corresponding to the particular product but not able to do so.

Can you tell me how to implement this functionality.

My view is:



 &lt;input id = &quot;quantity&quot; name=&quot;productprice[quantity]&quot; type=&quot;text&quot; value=&quot;&quot;&gt;
 &lt;input id = &quot;price&quot; name=&quot;productprice[price]&quot; type=&quot;text&quot; value=&quot;&quot; /&gt;



But i am not able to access these quantities and prices in controller.

Please help me in implementing the functionality.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I want to insert multiple rows at once in the database. My functionality is to add product prices against different quantities. I have a table named productprices in the database. Now I require to insert product_id, quantity and price in the table as number of times as there are quantities corresponding to the particular product but not able to do so.</p>
<p>Can you tell me how to implement this functionality.</p>
<p>My view is:</p>
<p> &lt;input id = &#8220;quantity&#8221; name=&#8221;productprice[quantity]&#8221; type=&#8221;text&#8221; value=&#8221;"&gt;<br />
 &lt;input id = &#8220;price&#8221; name=&#8221;productprice[price]&#8221; type=&#8221;text&#8221; value=&#8221;" /&gt;</p>
<p>But i am not able to access these quantities and prices in controller.</p>
<p>Please help me in implementing the functionality.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: O'Malley</title>
		<link>http://og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/comment-page-1/#comment-49</link>
		<dc:creator>O'Malley</dc:creator>
		<pubDate>Sat, 21 Jul 2007 03:33:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/#comment-49</guid>
		<description>Why yes I do.  Here&#039;s a hint.  Checkboxes are not what you need.  Try radio.</description>
		<content:encoded><![CDATA[<p>Why yes I do.  Here&#8217;s a hint.  Checkboxes are not what you need.  Try radio.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ravvuinn</title>
		<link>http://og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/comment-page-1/#comment-48</link>
		<dc:creator>ravvuinn</dc:creator>
		<pubDate>Sat, 21 Jul 2007 00:42:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/#comment-48</guid>
		<description>Hey!  Almost informative for my purpose....  was wondering if you know how to do the following:

build a quiz question with five multiple choice answers, using checkboxes to pass the correct answer_id into the correct answer_id column in the questions table.</description>
		<content:encoded><![CDATA[<p>Hey!  Almost informative for my purpose&#8230;.  was wondering if you know how to do the following:</p>
<p>build a quiz question with five multiple choice answers, using checkboxes to pass the correct answer_id into the correct answer_id column in the questions table.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: varma</title>
		<link>http://og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/comment-page-1/#comment-47</link>
		<dc:creator>varma</dc:creator>
		<pubDate>Fri, 13 Jul 2007 12:41:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/#comment-47</guid>
		<description>in rhtml---


    &quot;line_cartitem[cartitem_id][]&quot;, :id =&gt; &quot;line_cartitem_id_#{Product.id}&quot;} %&gt;
in controller---
def select
      @product = Product.new(params[:product])
      @product.order_id  = @session[&quot;order_id&quot;]
      for cartitem_id in params[:product_cartitem][:cartitem_id] do
        @product.product_cartitems  cartitem_id)
      end
      if @product.save
        flash[:notice] = &#039;selected items was saved&#039;
redirect_to :action =&gt; &#039;add_to_cart&#039;
else
   render :action =&gt; &#039;index&#039;
   end
        end


i am geeting error as
   undefined method `order_id=&#039; for #</description>
		<content:encoded><![CDATA[<p>in rhtml&#8212;</p>
<p>    &#8220;line_cartitem[cartitem_id][]&#8220;, :id =&gt; &#8220;line_cartitem_id_#{Product.id}&#8221;} %&gt;<br />
in controller&#8212;<br />
def select<br />
      @product = Product.new(params[:product])<br />
      @product.order_id  = @session["order_id"]<br />
      for cartitem_id in params[:product_cartitem][:cartitem_id] do<br />
        @product.product_cartitems  cartitem_id)<br />
      end<br />
      if @product.save<br />
        flash[:notice] = &#8216;selected items was saved&#8217;<br />
redirect_to :action =&gt; &#8216;add_to_cart&#8217;<br />
else<br />
   render :action =&gt; &#8216;index&#8217;<br />
   end<br />
        end</p>
<p>i am geeting error as<br />
   undefined method `order_id=&#8217; for #</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mahesh</title>
		<link>http://og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/comment-page-1/#comment-46</link>
		<dc:creator>mahesh</dc:creator>
		<pubDate>Fri, 13 Jul 2007 12:38:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/#comment-46</guid>
		<description>hai
  thank u for giving the detailed explation on this, but when i done the same as u did its geeting an error. i am trying for three days please help me

  Errorundefined method `order_id=&#039; for #</description>
		<content:encoded><![CDATA[<p>hai<br />
  thank u for giving the detailed explation on this, but when i done the same as u did its geeting an error. i am trying for three days please help me</p>
<p>  Errorundefined method `order_id=&#8217; for #</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Florian</title>
		<link>http://og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/comment-page-1/#comment-45</link>
		<dc:creator>Florian</dc:creator>
		<pubDate>Wed, 27 Sep 2006 11:19:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/#comment-45</guid>
		<description>Ahh, I hate commentsystems without preview because I&#039;m to lazy to read my source in this tiny textbox...

&lt;code&gt;-class InvoiceItem
+class InvoiceItem &lt; Item&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Ahh, I hate commentsystems without preview because I&#8217;m to lazy to read my source in this tiny textbox&#8230;</p>
<p><code>-class InvoiceItem<br />
+class InvoiceItem &lt; Item</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Florian</title>
		<link>http://og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/comment-page-1/#comment-44</link>
		<dc:creator>Florian</dc:creator>
		<pubDate>Wed, 27 Sep 2006 11:16:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/#comment-44</guid>
		<description>If you do STI you could possibliy say:
&lt;code&gt;@invoice.invoice_items = InvoiceItems.find params[:invoice_items]&lt;/code&gt;
Wherefor you tell your InvoiceItem Model:
&lt;code&gt;class InvoiceItem
And finally change the name of your checkbox tag:
&lt;/code&gt;&lt;code&gt;&lt;%= check_box_tag ‘line_item’, item.id, checked=false, {:name =&gt; &quot;invoice_items[]&quot;, :id =&gt; &quot;line_item_id_#{item.id}&quot; } %&gt;&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>If you do STI you could possibliy say:<br />
<code>@invoice.invoice_items = InvoiceItems.find params[:invoice_items]</code><br />
Wherefor you tell your InvoiceItem Model:<br />
<code>class InvoiceItem<br />
And finally change the name of your checkbox tag:<br />
</code><code>&lt;%= check_box_tag ‘line_item’, item.id, checked=false, {:name =&gt; "invoice_items[]", :id =&gt; "line_item_id_#{item.id}" } %&gt;</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: O'Malley</title>
		<link>http://og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/comment-page-1/#comment-43</link>
		<dc:creator>O'Malley</dc:creator>
		<pubDate>Thu, 27 Jul 2006 13:02:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.og-consulting.com/2006/03/09/ruby-on-rails-insert-multiple-child-records/#comment-43</guid>
		<description>Thanks for the tip, whoever (if that is your real name :-) )  Active Record is indeed an amazing thing.

Thanks for the heads up on transaction</description>
		<content:encoded><![CDATA[<p>Thanks for the tip, whoever (if that is your real name <img src='http://og-consulting.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  )  Active Record is indeed an amazing thing.</p>
<p>Thanks for the heads up on transaction</p>
]]></content:encoded>
	</item>
</channel>
</rss>
