{"action":"created","issue":{"url":"https://api.github.com/repos/rubytaiwan/AMA/issues/64","labels_url":"https://api.github.com/repos/rubytaiwan/AMA/issues/64/labels{/name}","comments_url":"https://api.github.com/repos/rubytaiwan/AMA/issues/64/comments","events_url":"https://api.github.com/repos/rubytaiwan/AMA/issues/64/events","html_url":"https://github.com/rubytaiwan/AMA/issues/64","id":112946057,"number":64,"title":"如何儲存多個不需sql動作的資料？","user":{"login":"viflin","id":5573816,"avatar_url":"https://avatars.githubusercontent.com/u/5573816?v=3","gravatar_id":"","url":"https://api.github.com/users/viflin","html_url":"https://github.com/viflin","followers_url":"https://api.github.com/users/viflin/followers","following_url":"https://api.github.com/users/viflin/following{/other_user}","gists_url":"https://api.github.com/users/viflin/gists{/gist_id}","starred_url":"https://api.github.com/users/viflin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/viflin/subscriptions","organizations_url":"https://api.github.com/users/viflin/orgs","repos_url":"https://api.github.com/users/viflin/repos","events_url":"https://api.github.com/users/viflin/events{/privacy}","received_events_url":"https://api.github.com/users/viflin/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rubytaiwan/AMA/labels/SQL","name":"SQL","color":"c7def8"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-10-23T04:01:57Z","updated_at":"2015-10-27T03:27:12Z","closed_at":null,"body":"大家好\r\n我需要儲存一筆沒什麼用但是又必須要儲存的資料\r\n所以我想要把它存成hash格式\r\n每個user有固定三個名稱為top, mid, adc的box， box有他自己的width, height, depth屬性\r\n\r\n```ruby\r\n=> user.box\r\n=> { \r\n      top=> { width=>1, height=>5, depth=>6 },\r\n      mid=> { width=>3, height=>2, depth=>7 },\r\n      adc=> { width=>8, height=>5, depth=>2 }\r\n   }\r\n```\r\n\r\n然後在user edit 的時候可以順便編輯他\r\n\r\n![edit page](http://i.imgur.com/Ty85IeQ.png)\r\n\r\n我嘗試過使用serialize，hstore 但是都沒有成功過\r\n目前使用hstore，box 欄位是hstore格式，\r\n只有達成輸入進去，但是edit的情況他不會顯示\r\n\r\n```ruby\r\n# user.rb\r\nclass Users <ActiveRecord::Base\r\n   store_accessor :box, top, :mid, :adc\r\nend\r\n```\r\n\r\n```slim\r\n# edit page slim\r\n= form_for :user do |f|\r\n  = f.fields_for :box do | box |\r\n    = box.fields_for :top do | top |\r\n       = top.text_field :width\r\n       = top.text_field :height\r\n       = top.text_field :depth \r\n    = box.fields_for :mid do | mid |\r\n       = mid.text_field :width\r\n       = mid.text_field :height\r\n       = mid.text_field :depth \r\n    = box.fields_for :adc do | adc |\r\n       = adc.text_field :width\r\n       = adc.text_field :height\r\n       = adc.text_field :depth \r\n```\r\n\r\n請問大家有沒有比較好的解法或是參考的資料，謝謝\r\n"},"comment":{"url":"https://api.github.com/repos/rubytaiwan/AMA/issues/comments/151361828","html_url":"https://github.com/rubytaiwan/AMA/issues/64#issuecomment-151361828","issue_url":"https://api.github.com/repos/rubytaiwan/AMA/issues/64","id":151361828,"user":{"login":"abookyun","id":2224554,"avatar_url":"https://avatars.githubusercontent.com/u/2224554?v=3","gravatar_id":"","url":"https://api.github.com/users/abookyun","html_url":"https://github.com/abookyun","followers_url":"https://api.github.com/users/abookyun/followers","following_url":"https://api.github.com/users/abookyun/following{/other_user}","gists_url":"https://api.github.com/users/abookyun/gists{/gist_id}","starred_url":"https://api.github.com/users/abookyun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abookyun/subscriptions","organizations_url":"https://api.github.com/users/abookyun/orgs","repos_url":"https://api.github.com/users/abookyun/repos","events_url":"https://api.github.com/users/abookyun/events{/privacy}","received_events_url":"https://api.github.com/users/abookyun/received_events","type":"User","site_admin":false},"created_at":"2015-10-27T03:27:12Z","updated_at":"2015-10-27T03:27:12Z","body":"看起來現在的問題是，不知道如何從 form 中編輯 hstore 的資料。找到一些資料可以參考：\r\n\r\n如果你是 Rails 3 可以看看 https://github.com/diogob/activerecord-postgres-hstore\r\n如果是 Rails 4 原生就有支援 hstore http://api.rubyonrails.org/classes/ActiveRecord/Store.html\r\n如果你用 SimpleForm https://gist.github.com/lucasdavila/3715290\r\n如果用純 form 的話看來可以用這個 https://coderwall.com/p/hnhd4w/hstore-and-rails-form"}}