rails/rails — pull request #5209 by losvedir (2012-02-28 18:19:52+00:00)
Title: Add check if value is frozen before attempting to mutate via encode!

This fixes the following error I was receiving (the "day" string, e.g., "Thursday" was frozen by rails, presumably because it's Encoding::ASCII_8BIT? Therefore, when it gets "encode!"-ed to utf-8, a RuntimeError occurs.). This is related to this stackoverflow question (http://stackoverflow.com/questions/9474730/rails-active-record-runtimeerror-cant-modify-frozen-string-somehow-related).

(0.1ms) begin transaction
Binary data inserted for `string` type on column `day`
SQL (0.5ms) INSERT INTO "availabilities" ("coach_id", "created_at", "day", "hour", "updated_at") VALUES (?, ?, ?, ?, ?) [["coach_id", 3], ["created_at", Tue, 28 Feb 2012 18:05:33 UTC +00:00], ["day", "Monday"], ["hour", 18], ["updated_at", Tue, 28 Feb 2012 18:05:33 UTC +00:00]]
RuntimeError: can't modify frozen String: INSERT INTO "availabilities" ("coach_id", "created_at", "day", "hour", "updated_at") VALUES (?, ?, ?, ?, ?)
(0.1ms) rollback transaction
Completed 500 Internal Server Error in 59ms