For such kind of requirements i prefer
1st) create a config/app_constants.yml
Code here
production:
time_list: "'7:00am','7:30am','7:40am'"
test:
time_list: "'7:00am','7:30am','7:40am'"
development:
time_list: "'7:00am','7:30am','7:40am'"
2nd Create under lib/app_constant.rb
module AppConstant
extend self
CONFIG_FILE = File.expand_path('../config/app_constants.yml', __FILE__)
@@app_constants = YAML.load(File.read(CONFIG_FILE))
@@constants = @@app_constants[Rails.env]
def get_time_list
@@constants['time_list'].split(',')
end
end
3rd Call it anywhere like
AppConstant.get_time_list #will return an array
With this you just have to make changes at a single clean place(app_constants.yml
) and will reflect throughout you application wherever AppConstant.get_time_list
is used