Reputation: 8487
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.
Upvotes: 8
Views: 13011
Reputation: 25294
./.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
Do not forget to set access privileges to execute ./start.sh
chmod +x ./start.sh
just run command from the root folder of your rails app:
./start.sh
Upvotes: 2
Reputation: 332
If you don't need the variable to be variating, you should put this into initializers or on a helper class. If you're looking for enviroment, you don't need it because it's the default.
Upvotes: 0
Reputation: 9747
You have various options to do so:
More info @ http://www.gotealeaf.com/blog/managing-environment-configuration-variables-in-rails
Upvotes: 2
Reputation: 13633
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.
Upvotes: 2