I'm building a Rails 3 application that will have user-specific settings (looks, functionality, etc) and I was seeking some simple advice on whats the preferred way of actually implementing settings.
Do you prefer to have a dedicated model for this stuff? Are hashes acceptable to store in a database field? Do you prefer cookies or sessions over the database? Is an STI object best?
Maybe list some pros or cons to each different method if you can.
Thanks.
i've same situation like you, user specific setting. In my apps i prefer creating a model to store user's configuration i've User model and User_configuration model, where the relationship is one-to-one.
class User < ActiveRecord::Base
has_one :user_configuration
end
class UserConfiguration < ActiveRecord::Base
belongs_to :user, :dependent => :destroy
end
Or if you prefer using Hash and store it to database is possible to mark your field as serialize
class User < ActiveRecord::Base
serialize :preferences, Hash
end
you can see it at http://api.rubyonrails.org/classes/ActiveRecord/Base.html
pros: - so far i've doesn't have any problem, it easy to maintenance
cons: - request more table in database
May be it could help you thanks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With