Deploy a Ruby on Rails App


This is a Hello World Rails 5.2 application that you can use as a starting point for your own Rails project on Render.

The sample app is deployed at https://rails.app.render.com.

  1. Create a new PostgreSQL database on Render.

  2. Fork render-examples/rails and create a new Web Service, giving Render’s GitHub app permission to access your forked repo.

  3. Use the following values during creation:

    Build Command: ./build.sh

    Here are the contents of the build script:

    #!/usr/bin/env bash
    bundle install
    
    bundle exec rake assets:precompile
    
    bundle exec rake assets:clean
    
    bundle exec rake db:migrate

    It’s simply executing commands needed to build a Rails site.


    Start Command: ./start.sh

    Here are the contents of the start script:

    #!/usr/bin/env bash
    bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}

    It starts puma with 5 threads and uses PORT and RACK_ENV which are environment variables automatically set by Render.


    Under the Advanced section, add two new environment variables:
    KeyValue
    SECRET_KEY_BASEA sufficiently strong secret. You can generate a secret locally by running bundle exec rake secret
    DB_URLThe internal connection string for the database you created above.

That’s it! Your web service will be live on your Render URL as soon as the build finishes.

A note on Ruby versions

By default, Render uses the latest LTS version of Ruby.

It can also automatically detect and install the version of Ruby specified in .ruby-version at the root of your project, or in your Gemfile.

This is the relevant snippet from the Gemfile in this repo:

ruby '2.5.3'