I have the following command. I insert it on starting the rails server
VARIABLE=development rails s
How do I make this variable start automatically, without having to wright it myself every time?
So I would then just do this
rails s
and it would run automatically with that variable.
You have various options to do so:
Declare your variables in .bashrc
file and reload it.
Use dotenv
gem.
Use figaro
gem.
More info @ http://www.gotealeaf.com/blog/managing-environment-configuration-variables-in-rails
Bundle the dotenv-rails gem, then create a .env
file with the content:
VARIABLE=development
The gem picks up all variables from the file and sets them in your environment.
./.env
APP_PORT=3000
APP_HOST=0.0.0.0
ENV=development
DATABASE_NAME=batman
DATABASE_USER=bat
DATABASE_PASSWORD=1234
DATABASE_PORT=5443
./start.sh
script that will run your rails app with all variables from ./.env
set -o allexport
source .env
set +o allexport
bundle exec rails s -p $APP_PORT -b $APP_HOST -e $ENV
set command info
Do not forget to set access privileges to execute ./start.sh
chmod +x ./start.sh
chmod command info
just run command from the root folder of your rails app:
./start.sh
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With