I’m serializing a hash that is stored in a settings field in a table, and would like to be able to edit that hash in a form field.
class Template < ActiveRecord::Base
serialize :settings
end
But I just do <%= f.text_area :settings %> then the text area just shows the serialized data instead of the hash.
How can I get the hash to show in the text area?
Maybe setting up another accessor for your model would work.
Then in your form use
<%= f.text_area :settings_edit %>.I have not tested any of this code, but in theory it should work. Good luck!
WARNING: Using
evallike this is very dangerous, in this example a user could delete the entire Template table with one line in the edit boxTemplate.destroy_all. Use a different method to convert the string to a hash if user input is involved.