Starting the Thor in Rails workspace

I want to do some work on rails 3 in production, but I don't know how to set it up. The following code did not work

class CheckData < Thor require File.expand_path('config/environment.rb') end 
+4
source share
1 answer

Setting the environment variable RAILS_ENV to "production" on the require statement should work. I used conditional assignment here so that the default environment is "production" if the environment variable is not set in advance.

 class CheckData < Thor ENV['RAILS_ENV'] ||= 'production' require File.expand_path('config/environment.rb') end 

If you run it as a Thor task from the command line, you can set the environment variable before starting and thus override the default assignment:

 export RAILS_ENV=test; thor check_data 

See the Rails Application Settings section of the Rails Environment Settings from RailsGuides for additional environment variables.

+6
source

Source: https://habr.com/ru/post/1336908/


All Articles