Inspired by http://12factor.net/config. Apps store user data in either a database or in files stored under a root directory dedicated to that app.
For each deployment (dev, test, prod, shared, etc.) the user's data will vary and thus should be in separate locations. To facilitate this, configuration is moved to environment variables i.e. environment variables will indicate where user data (files and database) is located.
- To manage setting the environment in Rails we'll use the
dotenv-rails
gem. -
$RAILS_DATAROOT
will specify the "data root" where files for the app can be created and managed. - When sharing an app, the sqlite3 database file will be created under this data root, but the
awesim
CLI will manage that, so in development you can keep using$RAILS_APP_ROOT/db/development.sqlite3
.
In order for an app to be sharable with others, it must make use of the $RAILS_DATAROOT
to store the user's files, as the deployed directory will not be writable by the user. Below are directions for updating your app to do this.