Running Rails on Replit
This guide helps with the steps to run a Ruby on Rails application on Replit. If you are starting from scratch, it is recommended that you use the existing Ruby on Rails template.
Starting from an existing GitHub repository
If you already have a Rails application stored in a GitHub repository and want to clone the repository into Replit, you'll need to do the following things:
- From the main menu, start by creating a Repl and importing your repository from GitHub. After you select Import from GitHub and cloning the repository, you will select the run command. If Replit detects your imported repository as a Rails application, it will automatically supply you with the appropriate run command. If not, for rails applications, use the following run command:
bundle exec rails server --binding=0.0.0.0
- he app should be bound to
0.0.0.0
instead oflocalhost
to be able to run on Replit. - The command is prefaced with
bundle exec
to run in the context of the installed gems. Any Rails commands you run must be prefaced withbundle exec
. - Once the run command is set, you will likely also need to install all the existing necessary packages by running the following command in the shell:
bundle install
- Once that is done, use the run button to run the application.
However, to fully utilize Replit's features, you must make two more changes.
- Allow
*.replit.dev
hosts by adding the following line toconfig/environments/development.rb
.
# Allow hosting on *.replit.dev hosts
config.hosts << /.*\.replit.dev/
2. Then, allow the app to be iframed on replit.com
by adding the following lines to config/application.rb
.
# Allow the app to be iframed on replit.com
config.action_dispatch.default_headers = {
'X-Frame-Options' => 'ALLOWFROM replit.com'
}
3. Now, when you run your app, a window should pop up displaying your application.
Running Commands
All commands must be prefaced by bundle exec
. This ensures that the command runs in the context of the installed gems environment. The console pane will give you output from the server, but you can run arbitrary commands from the shell without stopping the server.
FAQ
Could not find the 'bundler' required by your 'Gemfile.lock'
The version of the bundler that your lock file requires is not the one we currently have on Replit. You can either install the appropriate version of the bundler or delete the Gemfile.lock
and then run bundle install
to reinstall the correct version of the necessary packages and also recreate the lock file.