开发者

Suggestion needed for keeping hash value in the table in rails

开发者 https://www.devze.com 2023-01-30 11:28 出处:网络
As an extension of the question How to retrieve the hash values in the views in rails I have some doubts of keeping hash values in the table..

As an extension of the question

How to retrieve the hash values in the views in rails

I have some doubts of keeping hash values in the table..

I have a user detail table where i am maintaining the additional details of the user in a column named additional_info in a hash format .. Will it be good in keeping like so...

As if the user scenario changes if the user wants to find开发者_JS百科 all the users under a particular project where i kept the project to which the user belongs in the hash format..

Give some suggestions..


Simple solution is to serialiaze it:

class FooBar < ActiveRecord::Base
# ...
  serialize :additional_info
#...
end

This internally uses the YAML serializer. You can assign any object that can be serialized using YAML.

foo = FooBar.first
foo.additional_info = {:foo => 'Lorem', :bar => 'ipsum'}
foo.save
foo.additional_info[:foo] # Gives 'Lorem'
0

精彩评论

暂无评论...
验证码 换一张
取 消