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は1レベル深すぎました...今では魅力のように機能します

于 2014-03-10T09:00:42.770 に答える