0

我的应用程序有一个大问题。它有点复杂,所以我将尝试深入解释它。在我的应用程序中,我有模型“汽车”:

class Car < ActiveRecord::Base

  has_many :prices,  dependent: :destroy

  accepts_nested_attributes_for :prices, allow_destroy: true

end

和“价格”:

class Price < ActiveRecord::Base
  belongs_to :car
end

我使用 wicked gem 来制作一个巫师表格。我还使用茧宝石轻松创建一些嵌套对象。我的“付款步骤html”:

= simple_form_for [:partners, @car], url: wizard_path do |f|
  = f.simple_fields_for :prices do |price|
    = render 'price_fields', f: price
  #links
    = link_to_add_association 'add price', f, :prices
  = link_to t('cars.back'), edit_partners_car_path(@car)
  = f.submit t('cars.next'), class: 'btn btn-primary'

和 price_fields:

.nested-fields
  %table.table.table-striped.table-bordered
    %thead
      %th
        = f.input :from_days
      %th  
        = f.input :to_days
      %th
        = f.input :netto_price
    = link_to_remove_association "X", f

问题是当我创建一些价格并进入下一步时,价格被保存到数据库中,一切都很好。但是当我回到这一步并点击我的:

= link_to_remove_association "X", f

它只隐藏这个对象,而不是从数据库中删除它。对我来说是个大问题。我找不到问题。如果可以的话请帮忙。

4

1 回答 1

0

我将“_price_fields”更改为:

.nested-fields
  %table.table.table-striped.table-bordered
    %thead
      %th
        = f.input :from_days
      %th  
        = f.input :to_days
      %th
        = f.input :netto_price
  = link_to_remove_association "X", f

我的 link_to_remove_association 太深了一层......现在就像魅力一样

于 2014-03-10T09:00:42.770 回答