# TypeError (can't modify frozen hash) - Production Mode Only

**URL:** <https://www.ruby-forum.com/t/typeerror-cant-modify-frozen-hash-production-mode-only/140432>\
**Category:** Rails\
**Created:** [June 13, 2008, 9:53pm UTC](https://www.ruby-forum.com/t/typeerror-cant-modify-frozen-hash-production-mode-only/140432 "2008-06-13T21:53:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lottario](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de053/32.png) [@lottario](https://www.ruby-forum.com/u/lottario)\
**Post date:** [June 13, 2008, 9:53pm UTC](https://www.ruby-forum.com/t/typeerror-cant-modify-frozen-hash-production-mode-only/140432/1 "2008-06-13T21:53:04Z")

</div>

Well, I’ve been testing out my code in production mode, in anticipation  
of being able to show off my site soon. Unfortunately, all is not going  
as expected. Production mode… well, its behaving differently than  
development did. I’ve already had login validation issues, and now it  
seems that my PM system is broken.

If a user enters a non-existent username as a recipient of a message, I  
now get a 500 internal server error. In the log, I get: TypeError  
(can’t modify frozen hash) at line 108. Line 108 is “@message.sender =  
find\_user\_and\_messages.get\_user\_id.to\_s”, which shouldn’t even be  
executing (its also a poorly named method, but thats not the point). In  
development mode, if a user didn’t exist, the while loop would recognize  
that, and simply return errors. Now it fails to do so. All my other  
validations on the message seem to work fine, its just this one that  
fails. The appropriate code:

```
  if
    #other validations on the message
  else
    while (i<hold.length)
      if User.find_by_screen_name(hold[i]) == nil
        @message.errors.add("Recipient " + hold[i] + " doesn't

```

exist!")  
@message.destroy  
break  
else  
if trfa == false  
@message.recipients = “,” +  
User.find\_by\_screen\_name(hold[i]).get\_user\_id.to\_s + “,”  
trfa = true  
else  
@message.recipients = @message.recipients +  
User.find\_by\_screen\_name(hold[i]).get\_user\_id.to\_s + “,”  
end  
i+=1  
end  
end  
@message.sender = find\_user\_and\_messages.get\_user\_id.to\_s  
@message.save  
flash[:notice] = “Message Sent!”  
redirect\_to hub\_url and return  
end

And as a secondary question, what is it that makes Rails behave  
differently in production mode? And how do I go about avoiding surprise  
behavior changes in future apps?

Thanks for your help in advance 🙂

---

<div class="post-metadata">

**Author:** ![lottario](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de053/32.png) [@lottario](https://www.ruby-forum.com/u/lottario)\
**Post date:** [June 13, 2008, 9:59pm UTC](https://www.ruby-forum.com/t/typeerror-cant-modify-frozen-hash-production-mode-only/140432/2 "2008-06-13T21:59:42Z")

</div>

Well, probably a poor fix, but I threw a boolean variable into every  
validation, and it only runs the lines that were giving a problem if the  
boolean hasn’t been changed, seems to fix the problem.

I’m still curious as to why there are differences between development  
and production mode though.
