Guest User

Untitled

a guest
Jun 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. class YourModel < ActiveRecord::Base
  2. require 'json'
  3.  
  4. def your_serialized_attribute=(hash)
  5. self[:your_serialized_attribute] = hash.to_json # This is actually what's going in to the database
  6. end
  7.  
  8. def your_serialized_attribute
  9. @serialized_attribute ||= JSON.parse(self[:your_serialized_attribute])
  10. end
  11. end
Add Comment
Please, Sign In to add comment