RoR:fields_for和partials
我正在使用nested_attributes将产品关联回交易。 我需要在产品模型中添加日期。我想添加一个链接以将 date_select 设置为今天。
这是视图:
<% f.fields_for :trans_products do |builder| %>
<%= render 'trans_product_fields', :f => builder %>
<% end %>
和部分:
<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>
???应该读取 transaction_trans_products_attributes_#number#,#number# 在文本字段中正确显示,po 文本字段读取 id="transaction_trans_products_attributes_0_po" 下一个 trans_product 具有 id="transaction_trans_products_attributes_1_po"
我如何将此计数器值获取到我的 link_to_function 参数中?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应该为您的集合自动设置一个 iteration_counter (您的集合在这里称为“trans_products”。
根据文档,计数器以数组中的项目命名,例如此处应称为“trans_product_counter”
有关更多信息,请查看此处:
http://apidock.com/rails/ActionView/Partials
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