1

My code is this

   leads_hash={"509351475764673"=>{"sc"=>0, "ct"=>#<OrderedHash {"2013-02-10"=>1}>, "ml"=>0}, "473882175995429"=>{"sc"=>0, "ct"=>0, "ml"=>0}}
    obj=User.new()
    obj.leads_hash=leads_hash

obj.save!

and in model i defined

class User < ActiveRecord::Base
 serialize :leads_hash
end

but it save as a string how can i solve this please someone help me

~

3
  • possible duplicate of Using Rails serialize to save hash to database Commented Feb 13, 2013 at 11:24
  • 1
    It will save as as a string in the database, but Rails will deserialize on load. What is the issue you have? Commented Feb 13, 2013 at 11:26
  • but its not deserialize for me ,when i fired this query data=User.find_by_id(1) and data.leads_hash.class.to_s it gives String Commented Feb 13, 2013 at 11:29

1 Answer 1

2

Make sure that leads_hash is stored as a text and not a string in your migration. For reference, check out a similar question: Using Rails serialize to save hash to database

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.