title: Why am I getting this 'can't modify frozen hash' error?
body: <p>I have a Person model &amp; an Item model. A person has many items, and an item belongs to a person.</p>
  
  <p>In this code, I need to delete the existing items for a person, and create new ones from a parameter (which is an array of hashes). Then, I need to update one of the item's fields, based on one of its other fields.</p>
  
  <pre><code>@person = Person.find(params["id"])
  
  @person.person_items.each do |q|
      q.destroy
  end
  
  person_items_from_param = ActiveSupport::JSON.decode(params["person_items"])
  
  person_items_from_param.each do |pi|
      @person.person_items.create(pi) if pi.is_a?(Hash)
  end
  
  @person.person_items.each do |x|
      if x.item_type == "Type1"
          x.item_amount = "5"
      elsif x.item_type == "Type2"
          x.item_amount = "10"
      end
      x.save
  end
  </code></pre>
  
  <p>On the <code>x.item_amount = "5"</code> &amp; <code>x.item_amount = "10"</code> lines I get this error:</p>
  
  <pre><code>RuntimeError in PersonsController#submit_items
  can't modify frozen hash 
  </code></pre>
  
  <p>How can I fix this? Thanks for reading.</p>