Saturday, June 28, 2025
News PouroverAI
Visit PourOver.AI
No Result
View All Result
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing
News PouroverAI
No Result
View All Result

How to deploy a Rails app to Render

March 5, 2024
in Front-Tech
Reading Time: 5 mins read
0 0
A A
0
Share on FacebookShare on Twitter



There are many ways to deploy a Ruby on Rails application to the internet. Between hosting on your own hardware, renting a virtual machine, using a cloud provider, and using a platform, the opportunities are endless. The low-hassle way to host a Rails application is to use a Platform as a Service (PaaS). In this article, we’ll show you how to deploy a Rails Application to Render.com, and as a bonus, monitor it with Honeybadger! You can find the final project here on Github. Going a step further than cloud hosting and using a platform to deploy your web apps provides incredible convenience at a cost. Under the hood, platforms such as Render and Heroku use Amazon Web Services or other cloud providers. Using a platform will cost you more than using a cloud provider directly, as the service is marked up. For the extra cost, you’ll be able to deploy and scale a functional service without needing to understand or manage the underlying infrastructure. You’ll also gain features like replication, autoscaling, and preview deployments without extra setup.

Cloud providers are complicated enough to have built an ecosystem around education and certification, while platforms like Render allow developers to deploy an application in a single sitting.

Setting up an example Ruby on Rails application

If you’re reading this, you likely already have a Rails app you’d like to deploy. In case you don’t, we’ll quickly go over creating a Rails app in this section.

If you don’t already have rails installed, install version 7.1.1 with:

“`html
gem install rails -v 7.1.1
“`

First, create a new Rails app using the `rails new` command. We’ll pass it a specific version:

“`html
rails _7.1.1_ new appname
“`

Next, go into the directory that was created:

“`html
cd appname
“`

Next, generate a new model and controller using the scaffold generator. For this example, we’ll model “Event”:

“`html
rails generate scaffold Event title:string date:datetime
“`

This creates a number of files to support Creating, Reading, Updating, and Deleting Event models in a database. We’ll run the created database migration to create the necessary Events table next with:

“`html
rake db:migrate
“`

The scaffold already generated basic views, models, and controllers to support CRUD actions on events. To see the code in action, run the rails server with:

“`html
rails server
“`

Now, visit localhost:3000/events in your browser. You’ll see a simple white page with an “Events” header and a “New event” button.

A screenshot of the Events Index Page

Clicking the button will take you to a form for creating the event, and creating the event will persist it in the database. You can also delete and edit an existing event, all from just the scaffold! This functional CRUD app will serve as a great example for our deployment. Push up the repository to Github as a final step.

Signing up for Render

Signing up for Render is easy. Signing up via Github will save you a step later, as we’ll connect to Github to deploy our app. Render’s free tier is generous, particularly for folks missing Heroku’s free tier. You can configure your service in the UI, or configure it in your codebase, using infrastructure as code. Many in the DevOps industry prefer infrastructure as code whenever possible, so we’ll do that in this example.

Configuring your deployment with deploy.yaml and build.sh

Add a file to the root of your repository called `render.yaml`. In that file, paste this:

“`html
databases:
– name: name_of_your_app
databaseName: name_of_your_app
user: name_of_your_app
plan: free

services:
– type: web
plan: free
name: name_of_your_app
env: ruby
buildCommand: “./bin/render-build.sh”
startCommand: “bundle exec puma -C config/puma.rb”
envVars:
– key: DATABASE_URL
fromDatabase:
name: name_of_your_app
property: connectionString
– key: RAILS_MASTER_KEY
sync: false
“`

In this file, replace `name_of_your_app` in all places with the name of your app. In our example, we’ll call it `event_tracker`. This specifies that you want a web service and database on the free plan. You’ll notice that the file references a build command in a file called `bin/render-build.sh`, which doesn’t exist yet. Create it, and paste the following:

“`html
#!/usr/bin/env bash

set -o errexit

bundle install
bundle exec rake assets:precompile
bundle exec rake assets:clean
bundle exec rake db:migrate
“`

This file will execute when your service starts, so they should go here if you need any other custom build steps.

Configuring Postgres as a database adapter

Rails applications begin using SQLite unless specified otherwise when generated. Render requires Postgres, so if your application doesn’t yet have it, you’ll need to add it. In your Gemfile, add `gem “pg”` to the main section of dependencies. Separately, move `gem “sqlite3”, “~> 1.4″` into `group: development`. Finally, run a `bundle install` to update Gemfile.lock.

You must also change your database configuration in `database.yml` to specify that Postgres should be used in production. Your `database.yml` should now look like this:

“`html
default: &default
adapter: postgresql
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000

development:
<<: *default adapter: sqlite3 database: db/development.sqlite3 test: <<: *default database: db/test.sqlite3 production: <<: *default database: event_tracker_production username: event_tracker password: <%= ENV['EVENT_TRACKER_DATABASE_PASSWORD'] %>
“`

You will need to swap out the value for the production database key, `event_tracker_production` with the name of your app, appended by production. You’ll also need to make the username, `event_tracker`, the name of your application. The environment variable for the production password should have the name of your app as `APP_NAME_PASSWORD`. Render will automatically set that environment variable with the appropriate value.

Deploying with the Render dashboard

Once you have pushed all your app changes to GitHub, it’s time to create your service in the Render dashboard. On the dashboard, select Blueprints, then “New Blueprint Instance.” This will allow us to create a new service using our `render.yml` file. Select the repository of the application you would like to deploy and give your blueprint a name. You’ll also need to paste in your Rails Master Key, which you can get from the file in your repository (which is not checked into git) titled `master.key`.

A screenshot of the Render dashboard

Paste in your master key, and let Render work its magic! In a few moments, your Rails application and its database will be live on the web. By default, Render will auto-deploy the service anytime a new commit is made to your default branch. Higher tiers of Render allow for more customization, like preview deployments.

Adding Honeybadger for monitoring

Honeybadger lets you quickly add application health monitoring to your app with minimal setup. After creating an account, add a new project in the dashboard.

A screenshot of the Honeybadger dashboard

After selecting your framework (Rails, in this case), you’ll be met with some instructions for setting it up. First, add the honeybadger gem by running:

“`html
gem install honeybadger
“`

Next, run the provided command to generate Honeybadger’s configuration files and send a test alert. Check in your changes and push them to GitHub, and Render will automatically deploy your application with Honeybadger!

To demonstrate the error monitoring, we can write a bug on purpose. For example, I can change my example application’s `events_controller.rb` to have an index method that references a class that I haven’t yet written:

“`html
def index
@events = Birthday.all
end
“`

Committing this and pushing it will auto-deploy the faulty code. After waiting a few minutes for the deploy, we can visit our application’s URL and append `/events` to visit the events index page that contains the bug. Bonus points if you can guess the Ruby error message!

Visiting the `/events` route throws an error, which is promptly reported to Honeybadger. The error, stack trace, URL, and other helpful information are easily accessible in Honeybadger.

A screenshot of the Honeybadger error page

Conclusion

In conclusion, deploying a Ruby on Rails application using Render offers a straightforward and efficient solution for developers looking to streamline their deployment process. This guide has walked you through setting up a basic Rails app, configuring it for deployment on Render, and integrating Honeybadger for monitoring. The process, though involved, is simplified by the platform’s user-friendly interface compared to cloud providers. As the web development landscape continues to evolve, tools like these help developers focus more on creating and less on the complexities of deployment and maintenance.



Source link

Tags: AppdeployRailsRender
Previous Post

This Gold Mining CEO Says His Company’s Stock is a ‘Once-In-A-Generation Buy,’ Seeks to Bounce Back from 5-Year Low

Next Post

‘No governance issues’: IIFL Finance’s Nirmal Jain calls RBI action on gold loans ‘a little harsh’

Related Posts

The essential principles of a good homepage
Front-Tech

The essential principles of a good homepage

June 7, 2024
How to measure and improve user retention
Front-Tech

How to measure and improve user retention

June 6, 2024
Push Animation on Grid Items
Front-Tech

Push Animation on Grid Items

June 5, 2024
How to build a Rails API with rate limiting
Front-Tech

How to build a Rails API with rate limiting

June 4, 2024
Introduction to the B.I.A.S. framework
Front-Tech

Introduction to the B.I.A.S. framework

June 3, 2024
Blue Ridge Ruby is exactly what we need
Front-Tech

Blue Ridge Ruby is exactly what we need

June 3, 2024
Next Post
‘No governance issues’: IIFL Finance’s Nirmal Jain calls RBI action on gold loans ‘a little harsh’

'No governance issues': IIFL Finance's Nirmal Jain calls RBI action on gold loans 'a little harsh'

Using generative AI to improve software testing | MIT News

Using generative AI to improve software testing | MIT News

This Machine Learning Paper Presents a General Data Generation Process for Non-Stationary Time Series Forecasting

This Machine Learning Paper Presents a General Data Generation Process for Non-Stationary Time Series Forecasting

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Trending
  • Comments
  • Latest
23 Plagiarism Facts and Statistics to Analyze Latest Trends

23 Plagiarism Facts and Statistics to Analyze Latest Trends

June 4, 2024
How ‘Chain of Thought’ Makes Transformers Smarter

How ‘Chain of Thought’ Makes Transformers Smarter

May 13, 2024
Amazon’s Bedrock and Titan Generative AI Services Enter General Availability

Amazon’s Bedrock and Titan Generative AI Services Enter General Availability

October 2, 2023
Is C.AI Down? Here Is What To Do Now

Is C.AI Down? Here Is What To Do Now

January 10, 2024
The Importance of Choosing a Reliable Affiliate Network and Why Olavivo is Your Ideal Partner

The Importance of Choosing a Reliable Affiliate Network and Why Olavivo is Your Ideal Partner

October 30, 2023
Managing PDFs in Node.js with pdf-lib

Managing PDFs in Node.js with pdf-lib

November 16, 2023
Can You Guess What Percentage Of Their Wealth The Rich Keep In Cash?

Can You Guess What Percentage Of Their Wealth The Rich Keep In Cash?

June 10, 2024
AI Compared: Which Assistant Is the Best?

AI Compared: Which Assistant Is the Best?

June 10, 2024
How insurance companies can use synthetic data to fight bias

How insurance companies can use synthetic data to fight bias

June 10, 2024
5 SLA metrics you should be monitoring

5 SLA metrics you should be monitoring

June 10, 2024
From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset

From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset

June 10, 2024
UGRO Capital: Targeting to hit milestone of Rs 20,000 cr loan book in 8-10 quarters: Shachindra Nath

UGRO Capital: Targeting to hit milestone of Rs 20,000 cr loan book in 8-10 quarters: Shachindra Nath

June 10, 2024
Facebook Twitter LinkedIn Pinterest RSS
News PouroverAI

The latest news and updates about the AI Technology and Latest Tech Updates around the world... PouroverAI keeps you in the loop.

CATEGORIES

  • AI Technology
  • Automation
  • Blockchain
  • Business
  • Cloud & Programming
  • Data Science & ML
  • Digital Marketing
  • Front-Tech
  • Uncategorized

SITEMAP

  • Disclaimer
  • Privacy Policy
  • DMCA
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2023 PouroverAI News.
PouroverAI News

No Result
View All Result
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing

Copyright © 2023 PouroverAI News.
PouroverAI News

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In