Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the preferred way to implement settings in a Ruby on Rails 3 application?

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.

like image 229
Branden Silva Avatar asked Apr 20 '11 06:04

Branden Silva


1 Answers

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.

like image 139
Agung Prasetyo Avatar answered Oct 14 '22 10:10

Agung Prasetyo