Branden Silva
Branden Silva

Reputation: 1406

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.

Upvotes: 6

Views: 353

Answers (2)

tommasop
tommasop

Reputation: 18765

If you want some structured solution you can either have a look at:

  1. Configurable Engine
  2. or rails-settings

Upvotes: 3

Agung Prasetyo
Agung Prasetyo

Reputation: 4483

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.

Upvotes: 4

Related Questions