The routes.rb is a ruby ββfile that is created once and loaded into memory.
You can simply add ruby ββcode to it and it will be executed once:
Rails.application.routes.draw do app_config = YAML.load_file("#{Rails.root}/config/application.yml")[Rails.env] constraints(:ip => %w[app_config['app_url']]) do .. my routes.. end end
This will create an instance of the routes.rb file with the variable loaded from yml and available in your rails routes application. You do not even need to use the env variable. A local variable seems like a better idea.
You can also put the logic inside and make it environment dependent:
if Rails.env.production? app_config = YAML.load_file("#{Rails.root}/config/application.yml")[Rails.env] constraints(:ip => %w[app_config['app_url']]) do .. my routes.. end else .. my routes ... end
source share