0 Replies - 822 Views - Last Post: 12 November 2014 - 12:33 AM Rate Topic: -----

#1 agstwn21   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 12-November 14

Environtment variable not show in Rails C

Posted 12 November 2014 - 12:33 AM

Hello guys, i'm new ruby u can say i'm noob :bigsmile:
I wanna ask about ruby on rails,
Environment variable can be set using application.yml

I have a code like this in application.yml

    defaults: &defaults
      STORE_URL: https://localhost:3000/
    
    development:
      <<: *defaults
    
    test:
      <<: *defaults
    
    production:
      <<: *defaults


and also set the configuration on application.rb

Bundler.require(*Rails.groups)
    
    if File.exists?(File.expand_path('../application.yml', __FILE__))
      config = YAML.load(File.read(File.expand_path('../application.yml', __FILE__)))
      config.merge! config.fetch(Rails.env, {})
      config.each do |key, value|
        ENV[key] ||= value.to_s unless value.kind_of? Hash
      end
    end


and add this code to .gitignore

    config/appication.yml
    .project


When i run on terminal to test ENV, by using this comman
rails c development

the output should be like this:

    [1] pry(main)> ENV
    => {"Test1"=>"Tester1",
        "Test2"=>"Tester2",
        "Test3"=>"Tester3"}



In Rails 3.0.20 and Ruby 1.9.3p545 it work so simple when i tested it by type or adding new Key and Value on application.yml .but, on Rails 4.1.5 and Ruby 2.0.0p541 it wont goes like that


Need Your Help Guys!
Thanks

Is This A Good Question/Topic? 0
  • +

Page 1 of 1