I'm creating a Ruby on Rails website and that i come with an "architectural" question : my application needs some parameters and I am wondering where you can store them.

In concrete terms, my application receive some demands that are examined after which sent. So, the Request model should have characteristics concerning these remedies : a validation status along with a delivering status. For example, validation status could be "recognized", "declined" or "waiting". Delivering status could be "sent", "waiting", "error throughout delivering" or things like that. I must store individuals status codes parameters somewhere, but I'm not sure what's the best answer.

I possibly could produce a model for every one and store them within the database (and getting an energetic record model ValidationStatus for example) but : would not it be a bite excessive to produce a database/model for storing data like this?

I possibly could also only use them within the code without "storing" them, I possibly could store these questions YAML file...

So, a far more simpler question: how can you cope with the application parameters in RoR?

You will find plenty of global configuration plug ins, many of them center around the thought of loading a YAML file sooner or later. Check this page, this plugin as well as this Railscast.

I insert them in the database. I've many of these, and they're all pretty straightforward lists of strings. The tables are the same - id, title, description.

I generate models on their behalf instead of getting a real model apply for each one of these. In application/models I've got a file known as active_record_enums.rb, which inside your situation would look something similar to this:


ACTIVE_RECORD_ENUMS.each do |classname|
  eval "class #{classname} < ActiveRecord::Base; end"
  classname.constantsize.class_eval do 
    # Add useful methods - id_for(name) and value_for(id) are handy

This file needs to be needed inside a config file somewhere apart from that it's pretty straightforward.

(Have since seen that rails cast pointed out above [episode 85] - it appears like a little more 'the rails way' than below)

Another approach would be to develop the present configuration mechanism in Rails. Allows presume you will find two kinds of configs:

  1. Application wide configs present with dev/test/push conditions
  2. Configs specific to envrionments dev/test/push

For that first scenario, products in "RAILS_ROOT + '/config/atmosphere.rb'" work. Just observe that what they are called are captialised so that they are Ruby constants. An alternative for this is possess a mention of the another file for the reason that atmosphere.rb file ...

require RAILS_ROOT + '/config/appConfigCommon.rb'

and put relevant config products for the reason that file. It has the benefit of having the ability to be recommended independant of Rails.

For scenario 2, an identical approach could be taken. Place products for rise in "RAILS_ROOT + '/config/conditions/development.rb'" or something like that like

require RAILS_ROOT + '/config/environments/appConfigDev.rb'

and put atmosphere specific products for the reason that needed file, ensuring they begin with caps. And stick to the same pattern for test/push (yet others if necessary).

The config products are directly available in sights and remotes (unsure about models) simply by while using constant title.

I'm not using Ruby but Let me tell you which i began out (in ASP.Internet) placing plenty of configurations inside a Web.Config file (much like a YAML). As time continued, though, the machine developed to the stage where different instances needed different configurations. So, the majority of them have migrated towards the database. So...if you will be implementing multiple cases of your website, I'd highly recommend keeping configurations inside a table of the database (mine just one record, with fields for a number of configurations). Basically tried this to begin, I'd have saved a lot of time.