views:

55

answers:

1

hi, i am using nested_attributes for an association of products back to a transaction. I need to add a date to the products model. I would like to add a link to set the date_select to today.

here is the view:

        <% f.fields_for :trans_products do |builder| %>
            <%= render 'trans_product_fields', :f => builder %>
        <% end %>

and the partial:

<tr class="fields">
    <td><%= f.text_field :po, :class => 'prodinfo' %></td>
    <td><%= f.text_field :so, :class => 'prodinfo' %></td>
    <td><%= f.text_field :product, :class => 'prodinfo' %></td>
    <td><%= f.text_field :serial, :class => 'prodinfo' %></td>
    <td class=bigprodinfo><%= f.date_select :pos_date, :include_blank => true, :order => [:month, :day, :year] %>

    <%= link_to_function("today", "set_today('#{????}','pos_date')", :class => "today_link")  %>    </td>
    <td><%= link_to_remove_product "remove", f %></td>          
</tr>

the ???? should read transaction_trans_products_attributes_#number#, #number# shows up correctly for the textfields, the po text field reads id="transaction_trans_products_attributes_0_po" the next trans_product has id="transaction_trans_products_attributes_1_po"

how can i get this counter value into my link_to_function parameter?

thx

A: 

There should be an iteration_counter automatically set up for your collection (your collection here being called "trans_products". According to the docs, the counter is named after the items in the array eg here it should be called "trans_product_counter"

For more info, have a look here: http://apidock.com/rails/ActionView/Partials

Taryn East