Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to store site specific information like site name, admin email, etc?

When creating say a cms application where website specific details will vary depending on the website, where should I be storing this information?

Things like: site name, support email, smtp settings, etc.?

like image 990
Blankman Avatar asked Mar 12 '11 19:03

Blankman


2 Answers

Assuming you mean configuration data for the application, here's what I do:

I create a config/app_config.yml file with my config information, like this:

site_name: This awesome site
support_email: [email protected]

Then, at the top of config/application.rb (right below the first 'require' statement), I add this:

# Load application-specific configuration from app_config.yml
require 'yaml'
APP_CONFIG = YAML.load(File.read(File.expand_path('../app_config.yml', __FILE__)))

Now, any time I need to access the configuration data, I can get to it via the APP_CONFIG hash, like so:

html = "For support, please e-mail #{APP_CONFIG['support_email']}"

Note, the above is for Rails 3. For rails 2, instead of loading the config in application.rb, you would put the statements into config/preinitializer.rb.

See http://asciicasts.com/episodes/226-upgrading-to-rails-3-part-2 for more details.

like image 116
Mike Fischer Avatar answered Sep 22 '22 23:09

Mike Fischer


Setting like this.

$ vi config/environments/development.rb
config.site_name = "Your Site Name"
config.site_url = "localhost:3000"

Also you can use 'application.rb' environments.

$ vi config/application.rb
module YourAppName
 class Application < Rails::Application
   config.site_name = "Your Site Name"

How to use it.

<%= YourAppName::Application.config.site_name %>
@url = YourAppName::Application.config.site_url

You can check your AppName from here

$ vi config/application.rb
module YourAppName
 class Application < Rails::Application
like image 24
ayumi Avatar answered Sep 19 '22 23:09

ayumi