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'
精彩评论