使用nested_form获取对象值 [英] Get object value with nested_form

查看:44
本文介绍了使用nested_form获取对象值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个嵌套表单(按订单付款),我想在编辑视图中测试嵌套表单(fields_for)中的值.但是问题是我无法检查每个对象,我可以这样做:

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 %>

推荐答案

如果我理解这个问题,则说明您正在编辑订单,并为付款设置了fields_for,并希望获取与fields_for相关联的付款实例.您可以通过如下调用object来做到这一点

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

这篇关于使用nested_form获取对象值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆