Capistrano environment variable

2019-05-13 22:11发布

I saw this Capistrano: Can I set an environment variable for the whole cap session?

And I am using this to set my variable

  set :default_environment, self[:default_environment].
    merge('PAYPAL_SANDBOX' => 'true')

I print self[:default_environment] and I get PAYPAL_SANDBOX correctly set

However, how could I test if rails server is running with that variable set?, I think is not working, because in another part I have

ENV['PAYPAL_SANDBOX'] ? 'development' : Rails.env

and I am getting into second part of this sentence, I mean is taking Rails.env instead of development

2条回答
Melony?
2楼-- · 2019-05-13 22:46

My solution was like this:

  1. Set global variable

    set :my_number, 23

  2. Get global variable

    puts "My number is #{fetch(:my_number)}"

查看更多
萌系小妹纸
3楼-- · 2019-05-13 22:56

I solved it like this:

  1. I created a file inside my server, just to mark it

    touch test_server
    
  2. Inside an initializer

    TEST_SERVER = `ls ~/test_server`.present?
    
  3. Then,

    TEST_SERVER ? 'development' : Rails.env
    
查看更多
登录 后发表回答