Skip to content

Instantly share code, notes, and snippets.

@brianburridge
Created June 30, 2011 13:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianburridge/1056243 to your computer and use it in GitHub Desktop.
Save brianburridge/1056243 to your computer and use it in GitHub Desktop.
An easy and flexible way to set global variables for a Rails app using Ostruct.
require "ostruct"
case RAILS_ENV
when "staging"
google_maps_key = 'staging google maps key'
support_email = 'support@email.com'
ssl_subdomain = 'secure'
original_subdomain = 'www'
when "production"
google_maps_key = 'production google maps key'
support_email = 'support@email.com'
ssl_subdomain = 'secure'
original_subdomain = 'www'
else
support_email = 'localhost'
google_maps_key = 'development google maps key'
ssl_subdomain = 'secure'
original_subdomain = 'www'
end
App = OpenStruct.new({
:settings => OpenStruct.new({
:page_limit => 25,
:ssl_subdomain => ssl_subdomain,
:original_subdomain => original_subdomain,
:google_maps_key => google_maps_key,
:support_email => support_email,
:html_default_title => 'Site Title'
})
})
# Use App.settings.page_limit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment