user1645023
user1645023

Reputation:

Save a Hash in Mysql using ruby and read as hash

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

~

Upvotes: 1

Views: 1856

Answers (1)

Benjamin Tan Wei Hao
Benjamin Tan Wei Hao

Reputation: 9691

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

Upvotes: 2

Related Questions