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. Ссылка на gem https://github.com/nathanvda/cocoon. У них очень хорошая документация, поэтому вам будет очень легко начать работу. Спасибо

Смежные вопросы