Set Rails Variable to Different Values for Different Capistrano Environments -
I have a rail app, which is set to deploy to Capitolano for one of two different servers (It depends on how the user chooses to deploy) I want to create an environmental variable for the rail app which changes based on the server on which the website has been deployed.
In my Captivan deployment (Config / Deploy .rb) file, I have a variable "step"
set: steps,% w (output staging)
I have tried to use this variable to set the variable if its in the environment (config / environment.rb) file: If <:
< Code> if (: stages == "staging") ENV ['GLOBAL_EMAIL'] = "Email1@domain.com" other ENV ['GLOBAL_EMAIL'] = "email2@domain.com" end
However, when I test it, rail should be # {ENV} ['GLOBAL_EMAIL']}
(as far as I can tell that the variable is not set or unreachable).
My question is that someone The reason is that: Do not have access to the steps, and if there is a better way / way to set the variable according to the environment?
Note that even if a staging and an i It is known, the production environment of both the environment rails (rail testing and production vaat) Do not insert the cover), so I can not do a test to see which environment is running on the rail, then set the variable.
In addition to the capiterno, deploy_to
.
set (: deploy_to) {"/ var / www / # {This is a general setup within my deployment script, where staging and production is deployed on the same server. You might try something like this:
Set (global_email) if the step == 'output' ENV ['GLOBAL_EMAIL'] ='email1@example.com 'Other ENV [' GLOBAL_EMAIL '] =' Email2@example.com 'and end
or any other way to deal with this way is to use deployment steps specific files.
# config / deploy / production .rb ENV ['GLOBAL_EMAIL'] = 'email1@example.com' # config / deploy / staging.rb ENV ['GLOBAL_EMAIL'] = 'email2@example.com'
Update
I did not look at the question mentioning the value in the rail. Certainly there is nothing to do with the rail, nor is there anything set in the Capistorno config file Railways are initially started because the capitals should be available only in the development environment.
There will be a proper way of doing this using a Rail Initalizer and when the Rail is booted, then set the variable.
# config / initializer / global_email.rb If Rails.env.production is? GLOBAL_EMAIL = 'email1@example.com' second GLOBAL_EMAIL = 'email2@example.com' and
Comments
Post a Comment