Load environment variables into .railsrc file?

I am trying to load an environment variable into my .railsrc file,

I defined my RAIL_UTILS_HOME env var in my .bash_profile for example

 export RAIL_UTILS_HOME='/Path/to/Rails/utils' 

Here is what I am trying to do in .railsrc to load the default rail template

 -T -m $RAIL_UTILS_HOME/template.irb 

However, my $RAIL_UTILS_HOME var is not expandable,

Any idea how to do this correctly?

+4
source share
1 answer

you should be able to access environment variables via ENV["RAIL_UTILS_HOME"] as to where you do this, so it should also work in a .railsrc file.

since there is no explicit template for the .railsrc file, I assume that you have something like this in your .irbrc file:

 railsrc_path = File.expand_path('~/.railsrc') if ( ENV['RAILS_ENV'] || defined? Rails ) && File.exist?( railsrc_path ) begin load railsrc_path rescue Exception warn "Could not load: #{ railsrc_path }" # because of $!.message end end 

this will load the ~/.railsrc when you start your rails console.

+1
source

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


All Articles