How do I pass an array to fields_for in Rails?

前端 未结 2 1924
离开以前
离开以前 2021-01-13 14:22

I want to use fields_for on a subset of records in an association.

I have a Month model, which has_many :payments.

But

2条回答
  •  春和景丽
    2021-01-13 15:07

    You can add additional association for large payments, for example:

    class Month < ActiveRecord::Base
      has_many :payments
      has_many :large_payments, :class_name => "Payment", :conditions => "value > 1000000"
    end
    

    After that you can use fields_for in common way:

    - fields_for :large_payments
    

    I think to encapsulate this logic on a model side is a better approach then in the view.

提交回复
热议问题