Il modello principale Ordine has_many Vendite. Quando voglio distruggere un Ordine, le vendite associate dovrebbe anche ottenere distrutta, ma ho sempre imbattuto in un errore quando si fa così:Rails4: Impossibile modificare l'hash congelato
RuntimeError in OrdersController#destroy
Can't modify frozen hash
Questa linea di get evidenziato: self.price = mrr * self.quantity.to_f
.
Distruggi tutti i record di vendita associati manualmente, passo dopo passo, senza errori. Dopo che nessuna vendita è stata associata, sono in grado di distruggere anche il record dell'Ordine.
Il modello Vendita:
class Sale < ActiveRecord::Base
belongs_to :order, inverse_of: :sales
validates :order, :product, :product_group, :presence => true
before_create :price
def price
mrr = Warehouse.where(:product => self.product).pluck(:mrr).shift.strip.sub(',', '.').to_f
self.price = mrr * self.quantity.to_f
end
end
Il modello Order:
class Order < ActiveRecord::Base
has_many :sales, dependent: :destroy, inverse_of: :order
end
tutte le idee? Grazie in anticipo!
Grazie mille! Che funzioni! – CottonEyeJoe