I am working on a Rails application that has user authentication which provides an administrators account. Within the administrators account I have made a page for sitewide settings.
I was wondering what the norm is for creating these settings. Say for example I would like one of the settings to be to change the name of the application name, or change a colour of the header.
What I am looking for is for someone to explain the basic process/method - not necessarily specific code - although that would be great!
There is pretty nice plugin/gem Settingslogic.
You can use these settings anywhere, for example in a model:
For general application configuration that doesn't need to be stored in a database table, I like to create a
config.yml
file within the config directory. For your example, it might look like this:This configuration file gets loaded from a custom initializer in config/initializers:
Rails 2.x:
Rails 3.x:
You can then retrieve the value using:
See this Railscast for full details.
Here's what I did, and it seems most people follow this approach too: http://kpumuk.info/ruby-on-rails/flexible-application-configuration-in-ruby-on-rails/