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.?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With