0
私は、3つのモデル取引、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
私は取引のための1つのフォームを持っているし、そのフォーム内で、私はCellphoneAttributeフォームを持っているとCellphoneAttributeの内側に、私はCellphoneEquipmentフォームを持っています。すべてがここまでうまくいっています。今、Jqueryを使ってCellPhoneEquipmentフォームを複数回開くようにします。私にこれを行う方法を教えてください。