Ruby-on-Rails is a full-stack server-side web application framework that includes everything needed to create a database-backed web application according to the Model-View-Controller (MVC) pattern.
Package | Version | License |
---|---|---|
Ruby | 3.2.0 | 2-clause BSD License |
Rails | 7.0.4.2 | MIT |
Puma | 6.0.2 | Custom |
Postgres | 12.4 | Postgres SQL |
Nginx | 1.17.10 | Custom |
Node.js | 12.19.0 | Custom |
Certbot | 0.40.0 | Apache 2 |
Click the Deploy to DigitalOcean button to create a Droplet based on this 1-Click App. If you aren’t logged in, this link will prompt you to log in with your DigitalOcean account.
In addition to creating a Droplet from the Ruby on Rails 1-Click App using the control panel, you can also use the DigitalOcean API. As an example, to create a 4GB Ruby on Rails Droplet in the SFO2 region, you can use the following curl
command. You need to either save your API access token) to an environment variable or substitute it in the command below.
curl -X POST -H 'Content-Type: application/json' \
-H 'Authorization: Bearer '$TOKEN'' -d \
'{"name":"choose_a_name","region":"sfo2","size":"s-2vcpu-4gb","image": "rubyonrails-20-04"}' \
"https://api.digitalocean.com/v2/droplets"
After your droplet is created, you can access your Ruby on Rails installation by typing the droplet’s IP address in your browser:
Note: If you see the Site can’t be reached error, give it 2-3 minutes and reload the page.
Ruby is configured to use vendored bundles. Log in as a rails user to interact with the default project environment:
$ su - rails
All gems are also installed under the rails user environment.
Nginx is configured to forward requests for rails to a local Unix socket. Nginx configuration is located at /etc/nginx/sites-enabled/rails
Ruby-on-Rails Droplet 1-Click uses Puma to host the default website. Puma is managed via systemd service located at /etc/systemd/system/rails.service
You can manage Puma service via:
$ systemctl restart rails.service
$ systemctl stop rails.service
$ systemctl start rails.service
If you already have a Ruby on Rails (further as RoR) project, you can follow the steps below to migrate it to your droplet.
Note: All droplet commands below are intended to be run as the root user
First of all, you should copy your project folder to the droplet, you can do this by either using a VCS like git or simply using scp
command:
$ scp -r /root/<your local ror project directory> root@<your droplet IP>:/home/rails/<your ror project name>
Next, ssh into your droplet and make sure to give user rails permissions to your new Ruby on Rails project:
$ chown -R rails:rails /home/rails/<your ror project name>
At this point you can log in as rails user to install necessary dependencies for your project.
After this, you will have to update the Rails service if you wish to run your project as a service. First, open service file:
$ vim /etc/systemd/system/rails.service
Next, locate WorkingDirectory and ExecStart fields. Set WorkingDirectory as the directory of your RoR project and set ExecStart to the command which you use to run your project, in the example below we use the most common command rails s
:
...
WorkingDirectory=/home/rails/<your ror project name>
ExecStart=/bin/bash -lc 'rails s'
...
Save file and exit.
Finally, you need to reload and restart the Rails service:
$ systemctl daemon-reload
$ systemctl restart rails.service
/etc/systemd/system/rails/service
.