title: Rails4: Can't modify frozen hash
body: <p>The <code>Order</code> model:</p>
  
  <pre><code>class Order &lt; ActiveRecord::Base
    has_many :sales, dependent: :destroy, inverse_of: :order
  end
  </code></pre>
  
  <p>has_many <code>Sale</code>s:</p>
  
  <pre><code>class Sale &lt; ActiveRecord::Base
    belongs_to :order, inverse_of: :sales
    validates :order, :product, :product_group, :presence =&gt; true
    before_create :price
  
    def price
      mrr = Warehouse.where(:product =&gt; self.product).pluck(:mrr).shift.strip.sub(',', '.').to_f
      self.price = mrr * self.quantity.to_f
    end
  end
  </code></pre>
  
  <p>When I destroy an <code>Order</code>, the associated <code>Sale</code>s should also be destroyed, but I ran into an error when doing so:</p>
  
  <pre><code>RuntimeError in OrdersController#destroy
  Can't modify frozen hash
  </code></pre>
  
  <p>This line is highlighted: <code>self.price = mrr * self.quantity.to_f</code>.</p>
  
  <p>Destroying all associated <code>Sale</code>s records manually step-by-step works without errors. After no <code>Sale</code> is associated anymore, I can destroy the <code>Order</code> record too.</p>
  
  <p>Any Ideas?</p>