I want to be able to save a params[:object] hash in a text field of a drafts table, to keep this hash saved and pull it out later. I want to know if it’s possible to do so that I get a hash out later, with functionality.
Right now, when I am saving a post in here, so I have the following line:
@draft = user.drafts.build(:content => params[:post])
This saves the params[:post] hash as:
"--- !map:ActiveSupport::HashWithIndifferentAccess \ntitle: asdfasdfasdf\ncontent: \"\"\ndiscussion_id: \"87\"\ndraft: \"false\"\n"
If I find the draft (ie d = Draft.find(1)) and then I try to pull this hash out, I just get the string value here.
Is there some way I can reform this into a hash? Or is there a better way to go about saving the params hash in the first place?
Thanks
Check out the class method
serializeinActiveRecord::Base:It should save a fair amount of time over doing this yourself!