Skip to main content

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:

  1. 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
  1. he app should be bound to 0.0.0.0 instead of localhost to be able to run on Replit.
  2. The command is prefaced with bundle exec to run in the context of the installed gems. Any Rails commands you run must be prefaced with bundle exec.
  3. 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
  1. 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.

  1. Allow *.replit.dev hosts by adding the following line to config/environments/development.rb.
# Allow hosting on *.replit.dev hosts
config.hosts << /.*\.replit.dev/

allow replit hosts 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'
}

allow app to be iframed on replit.com 3. Now, when you run your app, a window should pop up displaying your application. rails popup window

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.

Was this helpful?