0

我有三种模型交易,CellPhoneAttribute和手机设备。 模型之间的关系是:Rails嵌套窗体(使用jquery)

class CellphoneEquipment < ActiveRecord::Base 
    belongs_to :cellphone_deal_attribute 
    end 

    class CellphoneAttribute < ActiveRecord::Base 
    has_many :cellphone_equipments, dependent: :destroy 
    accepts_nested_attributes_for :cellphone_equipments, :reject_if => :reject_equipment, allow_destroy: true 

    def reject_equipment(attributes) 
     if attributes[:model].blank? 
     if attributes[:id].present? 
      attributes.merge!({:_destroy => 1}) && false 
     else 
      true 
     end 
     end 
    end 
    end 

class Deal < ActiveRecord::Base 
    has_many :cellphone_deal_attributes, dependent: :destroy 
    accepts_nested_attributes_for :cellphone_deal_attributes,:reject_if => :reject_cellphone, allow_destroy: true 

    private 
    def reject_cellphone(attributes) 
     if attributes[:domestic_call_minutes].blank? 
     if attributes[:id].present? 
      attributes.merge!({:_destroy => 1}) && false 
     else 
      true 
     end 
     end 
    end 
end 

我有一个交易的形式和这种形式里面我有CellphoneAttribute形式和内部CellphoneAttribute我有CellphoneEquipment形式。一切都很好,直到这里。现在,我希望CellPhoneEquipment表单可以通过Jquery多次打开。请指导我如何做到这一点。

回答

0

尝试使用茧宝石。它使用jQuery处理动态嵌套表单。这里是链接到宝石https://github.com/nathanvda/cocoon。他们有一个非常好的文档,所以你会很容易开始。谢谢