Question

I'm trying to set a rails environment variable in a separate yml file. and it looks like this:

test:
  sap_url: "http://example.com/"

development:
  show_evp: 'true'
  show_social_media: "true"

production:
  show_evp: 'true'
  show_social_media: "true"

staging:
  show_evp: 'true'
  show_social_media: "true"

And in my rails admin I do the following

  config.model Settings do
    weight 1
    list do
      field :id
      field :show_hot_jobs
      if ENV['SHOW_EVP'] == 'true'
        field :show_evp
      end
      field :show_students
      field :show_testimonials
      field :show_on_boarding
    end

But the variable is always false, anyone have an idea of where I need to set these rails env variables or what is wrong with mine.

Kr, Vincent

Was it helpful?

Solution 2

Thanks for your help. I have created a .yml file in the config folder added all the settings that I need for dev / staging / prod.

Next in the lib folder created a module and did the following:

  def self.config
    OpenStruct.new \
    :url => yaml["url"]
  end

and now I can use it via "ModuleName".config.url

Kr, Vince

OTHER TIPS

Use Figaro gem to handle ENV variables and private data. Simple and easy. You won't regret.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top