我的hstore列widget_locations
中的值已低于:
"left_area2"=>"{\"youtube\"=>{:youtube_id=>\"aasdsadsa\", :from=>\"100\", :to=>\"200\"}}"
使用以下方法保存:
@webcast.create(:widget_locations => {:left_area2 => {:youtube => {:youtube_id => "aasdsadsa", :from => "100", :to => "200"}}})
我尝试通过
检索@webcast.left_area2
现在正在返回
"{\"youtube\"=>{:youtube_id=>\"aasdsadsa\", :from=>\"100\", :to=>\"200\"}}"
有没有办法将其更改为Rails数组?
答案 0 :(得分:0)
如果没有看到您的Webcast
模型,我猜您没有在serialize
上使用widget_locations
,因为hstore列应返回Hash
。
将serialize :widget_locations, ActiveRecord::Coders::Hstore
添加到模型的顶部并重新启动服务器 - 至少应该返回一个对象(例如Hash
)而不是字符串。