Greg Molnar has written a neat article about
creating a single-file Rails app
Show archive.org snapshot
.
This is not meant for production use but can be useful to try things out, e.g. when hunting down a bug or embedding a Rails app into the tests of a gem.
What you do is basically:
.ru
file, like app.ru
.rackup app.ru
. (Hint: if your file is called config.ru
, you can just run rackup
).There are some caveats to keep in mind:
It will run in whatever Ruby version is active for you. That may be fine locally.
Lock to a specific version by creating a .ruby-version
or whatever you need.
Gems and (especially) dependencies will be resolved to their latest version. I recommend creating a Gemfile
and moving the gem definition into it so you'll have a Gemfile.lock
. Then, run it via
bundle exec rackup app.ru
You might run into Bundler errors when multiple versions of a gem are installed for your current ruby:
You have already activated rack 1.4.7, but your Gemfile requires rack 2.2.4.
That can also be resolved by using a separate Gemfile
and bundle exec rackup
.
Your application is running in the development
environment by default. You can use RAILS_ENV=... rackup
to change that.