[英]Rails 4, cocoon gem destroying created objects
I have a big problem in my applications. 我的应用程序有个大问题。 It's little complicated so I will try explain it deeply.
它有点复杂,所以我将尝试深入解释。 In my application I have model "Car":
在我的应用程序中,我有模型“ Car”:
class Car < ActiveRecord::Base
has_many :prices, dependent: :destroy
accepts_nested_attributes_for :prices, allow_destroy: true
end
and "Price": 和“价格”:
class Price < ActiveRecord::Base
belongs_to :car
end
Im using wicked gem to have a wizard form. 我正在使用邪恶的宝石制作巫师表格。 Im also use a cocoon gem to easily create some nested objects.
我还使用茧子宝石轻松创建一些嵌套对象。 My "Payment step html":
我的“付款步骤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'
And price_fields: 和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
And the problem is when I create some prices and go to the next step prices are saved into databse and everything is fine. 问题是当我创建一些价格并进行下一步时,价格已保存到数据库中,一切都很好。 But when I come back to this step and I click my:
但是,当我回到这一步并单击我的:
= link_to_remove_association "X", f
it only hide this object but not delete it from database. 它只会隐藏该对象,而不会从数据库中删除它。 It's big problem for me.
对我来说这是个大问题。 I can't find issue.
我找不到问题。 Please help if You can.
如果可以的话请帮忙。
i change my "_price_fields" to: 我将“ _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
my link_to_remove_association it was one level too deep... Now works like charm 我的link_to_remove_association太深了一级...现在像魅力一样工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.