ruby - Store Global Variables for different environments in Rails -
in rails application try test calls redis. example in user model have:
def self.add_to_visibles user #to show in menu $redis.lpush("user_visibles", user.to_json(only: [:vorname, :nachname, :id, :created_at])) end
now when run test, test data inserted redis store "user_visibles"
. means when on development see data.
thats why change method to:
def self.add_to_visibles user #to show in menu $redis.lpush($user_visibles, user.to_json(only: [:vorname, :nachname, :id, :created_at])) end
and store in $user_visibles
:
for test: $user_visibles = "user_visibles_test"
and production $user_visibles = "user_visibles"
where best store variable? , how different environments?
i'd this:
config/user_variables.rb
rails.configuration.user_variable = yaml::load_file("#{rails.root}/config/user_variables.yml")[rails.env]
and create config/user_variables.yml this
production: 'user_visibles' test: 'user_visibles_test'
remember restart server
you have value rails.configuration.user_variable need it
Comments
Post a Comment