Rails configure Timezone from YML file -



Rails configure Timezone from YML file -

i have rails 3.2.x app default timezone set in application.rb config.time_zone = 'central time (us & canada)'

i spinning new servers in other timezones , need figure out how read timezone configuration company.yml file set company attributes while still using same github repo ease of management.

for each server have next file in config/initializers/company.rb

default_company = { company_name: "changeme", company_phone: "000-000-0000", company_email: "default_email@example.net", logo_path: "public/logo_changeme.png", no_reply_email: "noreply@example.com" } file_name = rails.root.join('config', 'company.yml') company = default_company.merge(yaml.load_file(file_name))

then have company.yml file contains specific settings each server instance phone call through app:

:company_name: 'john's company' :company_phone: '281-314-0000' :logo_path: 'public/logo.png' :company_email: 'company@example.net' :no_reply_email: 'noreply@example.com'

i want able set timezone configuration company.yml file or configuration file can maintain github repo static. tried following

company.yml

:company_name: 'john's company' :company_phone: '281-314-0000' :logo_path: 'public/logo.png' :company_email: 'company@example.net' :no_reply_email: 'noreply@example.com' :company_timezone: 'eastern time (us & canada)'

and in config/application.rb file attempted following:

config.time_zone = company[:company_timezone]

but when start server get: invalid timezone: company[:company_timezone] (argumenterror)

so tried next in config/application.rb: config.time_zone = "#{company[:company_timezone]}"

when start server uninitialized constant myapp::application::company (nameerror)

so question is, how can utilize company.yml file each server in different timezones set config/application.rb timezone? have syntax errors? or there way set timezone configuration file application.rb?

my other thought create multiple git/github repos 1 each instance , manually set timezone in application.rb. create nightmare of having maintain multiple repos going same app.

if question , description not clear, please allow me know. summarize, i'm trying set config.time_zone dynamically company.yml file loaded initializer. seem hitting wall.

thanks in advance help can offer or ideas may have.

i think found solution.

so in application.rb file require yaml , load company.yml file so

application.rb excerpt

require file.expand_path('../boot', __file__) require 'yaml' company = yaml.load(file.read(file.expand_path('../company.yml', __file__))) require 'rails/all' if defined?(bundler) # if precompile assets before deploying production, utilize line bundler.require(*rails.groups(:assets => %w(development test))) # if want assets lazily compiled in production, utilize line # bundler.require(:default, :assets, rails.env) end module myapp class application < rails::application # settings in config/environments/* take precedence on specified here. # application configuration should go files in config/initializers # -- .rb files in directory automatically loaded. # custom directories classes , modules want autoloadable. # config.autoload_paths += %w(#{config.root}/extras) # load plugins named here, in order given (default alphabetical). # :all can used placeholder plugins not explicitly named. # config.plugins = [ :exception_notification, :ssl_requirement, :all ] # activate observers should running. # config.active_record.observers = :cacher, :garbage_collector, :forum_observer # set time.zone default specified zone , create active record auto-convert zone. # run "rake -d time" list of tasks finding time zone names. default utc. config.time_zone = "#{company[:company_timezone]}"

however, when spin server receive next error:

config/initializers/company.rb:10: warning: initialized constant company

so since i'm loading company.yml file inapplication.rbwould need remove theconfig/initializers/company.rb` ?

ruby-on-rails ruby-on-rails-3 git github timezone

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -