<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Rails Forum - Ruby on Rails Help and Discussion Forum - fields_for need index of loop]]></title>
		<link>http://railsforum.com/viewtopic.php?id=40499</link>
		<description><![CDATA[The most recent posts in fields_for need index of loop.]]></description>
		<lastBuildDate>Sun, 22 Aug 2010 22:18:46 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: fields_for need index of loop]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=129777#p129777</link>
			<description><![CDATA[<p>Turns out that may not be the best idea, when you call the method it increments the counter which will cause problems with your form.</p><p>There&#039;s a ticket about this <a href="https://rails.lighthouseapp.com/projects/8994/tickets/3426-current-child-index-on-fields_for-nested-attributes">here</a> with a patch and a suggested workaround:</p><div class="codebox"><pre><code>f.object_name.gsub(/[^0-9]+/,&#039;&#039;)</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (rob-twf)]]></author>
			<pubDate>Sun, 22 Aug 2010 22:18:46 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=129777#p129777</guid>
		</item>
		<item>
			<title><![CDATA[Re: fields_for need index of loop]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=129740#p129740</link>
			<description><![CDATA[<p>Thanks.<br />I tried your suggestion, it says that the method private...</p><p>private method `nested_child_index&#039; called for #&lt;ActionView::Helpers::FormBuilder:0x48fef10&gt;</p><p>I have heard you can work around that. I will look into that.</p>]]></description>
			<author><![CDATA[dummy@example.com (gmcc)]]></author>
			<pubDate>Sat, 21 Aug 2010 03:41:41 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=129740#p129740</guid>
		</item>
		<item>
			<title><![CDATA[Re: fields_for need index of loop]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=129728#p129728</link>
			<description><![CDATA[<p><a href="http://apidock.com/rails/ActionView/Helpers/FormBuilder/nested_child_index">nested_child_index</a> looks like it might do the job:</p><div class="codebox"><pre><code>&lt;%= link_to_function(&quot;today&quot;, &quot;set_today(#{f.nested_child_index},&#039;pos_date&#039;)&quot;, :class =&gt; &quot;today_link&quot;)  %&gt;</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (rob-twf)]]></author>
			<pubDate>Fri, 20 Aug 2010 20:52:30 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=129728#p129728</guid>
		</item>
		<item>
			<title><![CDATA[fields_for need index of loop]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=129726#p129726</link>
			<description><![CDATA[<p>hi,</p><p>I need the &quot;counter&quot; for my fields_for loop to plug into a javascript function in the partial.</p><p>VIEW:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;% f.fields_for :trans_products do |builder| %&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;%= render &#039;trans_product_fields&#039;, :f =&gt; builder %&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;% end %&gt;</p><p>f is a transaction, trans_products belongs_to transaction, transaction accepts_nested_attributes_for trans_products.</p><p>so in the PARTIAL:</p><p>&lt;tr class=&quot;fields&quot;&gt;<br />&nbsp; &nbsp; &lt;td&gt;&lt;%= f.text_field :po, :class =&gt; &#039;prodinfo&#039; %&gt;&lt;/td&gt;<br />&nbsp; &nbsp; &lt;td&gt;&lt;%= f.text_field :so, :class =&gt; &#039;prodinfo&#039; %&gt;&lt;/td&gt;<br />&nbsp; &nbsp; &lt;td&gt;&lt;%= f.text_field :product, :class =&gt; &#039;prodinfo&#039; %&gt;&lt;/td&gt;<br />&nbsp; &nbsp; &lt;td&gt;&lt;%= f.text_field :serial, :class =&gt; &#039;prodinfo&#039; %&gt;&lt;/td&gt;<br />&nbsp; &nbsp; &lt;td class=bigprodinfo&gt;&lt;%= f.date_select :pos_date, :include_blank =&gt; true, :order =&gt; [:month, :day, :year] %&gt;<br />&nbsp; &nbsp; &lt;%= link_to_function(&quot;today&quot;, &quot;set_today(#{?????},&#039;pos_date&#039;)&quot;, :class =&gt; &quot;today_link&quot;)&nbsp; %&gt;&nbsp; &nbsp; &lt;/td&gt;<br />&nbsp; &nbsp; &lt;td&gt;&lt;%= link_to_remove_product &quot;remove&quot;, f %&gt;&lt;/td&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&lt;/tr&gt;</p><p>the ???? should read transaction_trans_products_attributes_#number#, #number# shows up correctly for the textfields, the po text field reads id=&quot;transaction_trans_products_attributes_0_po&quot; the next trans_product row has id=&quot;transaction_trans_products_attributes_1_po&quot;</p><p>how can i get this counter value into my link_to_function parameter?</p>]]></description>
			<author><![CDATA[dummy@example.com (gmcc)]]></author>
			<pubDate>Fri, 20 Aug 2010 20:19:09 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=129726#p129726</guid>
		</item>
	</channel>
</rss>
