0

Ich habe drei Modelle Angebote, CellPhoneAttribute und Handy-Equipment. Die Beziehung zwischen Modelle sind:Rails verschachtelte Form (mit 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 

Ich habe eine Form für die Menge und im Inneren dieser Form habe ich CellphoneAttribute Form und innen CellphoneAttribute habe ich CellphoneEquipment bilden. Bis hier funktioniert alles gut. Nun möchte ich das CellPhoneEquipment-Formular mehrmals über Jquery öffnen. Bitte führe mich, wie das geht.

Antwort

0

Versuchen Sie, den Cocoon-Edelstein zu verwenden. Es verarbeitet dynamisch verschachtelte Formulare mit jQuery. Hier ist der Link zu Edelstein https://github.com/nathanvda/cocoon. Sie haben eine sehr gute Dokumentation, so dass es sehr leicht für Sie ist, anzufangen. Danke

Verwandte Themen