Get object value with nested_form

心不动则不痛 提交于 2019-12-07 07:20:49

问题


I have a nested form (payments in an order) and I would like to test a value in my nested forms (fields_for) in edit view. But the problem is that I am not able to check each, I can just do this:

<% if @order.payments[0].monthly == false %>

Do you now how it is possible to check for each, like:

<% if @order.payments[current_payment].monthly == false %>

回答1:


If I understand the question, you are editing an order and have a fields_for for the payments and want to get the payment instance associated with the fields_for. You can do that by calling object like below

= form_for @order do |f|
  = f.fields_for :payments do |ff|
    - payment_for_this_fields_for = ff.object # current payment object


来源:https://stackoverflow.com/questions/15208161/get-object-value-with-nested-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!