Ruby
Completed
-
Section 1: Getting Started
-
Section 2: Core Syntax
-
Section 3: Methods and Blocks
-
Section 4: Object-Oriented Ruby
-
Section 5: Metaprogramming
-
Section 6: Working with Data and Files
-
Section 7: Ruby Frameworks Overview
-
Section 8: Ecosystem and Testing
-
Section 9: Practical Projects
-
Section 10: Interview Practice
-
Section 11: Data Structures and Algorithms in Ruby
-
Section 12: More Practice Exercises
-
Section 13: Enumerable and Functional Style
-
Section 14: More OOP Practice
-
Section 15: More Testing
-
Section 16: Enumerable and Comparable Modules In Depth
-
Section 17: Ruby Standard Library: Core Utilities
-
Section 18: Ruby Standard Library: Data and Security
-
Section 19: Ruby Standard Library: CLI and Text
-
Section 20: Ruby Networking
-
Section 21: Ruby on Rails Deep Dive
-
Section 22: Ruby Metaprogramming Deep Dive
-
Section 23: Ruby Design Patterns
-
Section 24: Ruby Concurrency
-
Section 25: Ruby Testing Deep Dive
-
Section 26: Ruby Gems and Packaging
-
Section 27: Ruby Performance
-
Section 28: More Practice Exercises
-
Section 29: More Interview Practice
-
Section 30: Rails API Development
-
Section 31: Rails Authentication and Authorization
-
Section 32: Rails Testing Deep Dive
-
Section 33: Rails Performance
-
Section 34: Rails Deployment
-
Section 35: Sinatra and Lightweight Ruby Web Apps
-
Section 36: More Ruby Language Deep Dive
-
Section 37: Ruby 3.x Modern Features
-
Section 38: More Data Structures in Ruby
-
Section 39: More Practical Projects
-
Section 40: Ruby Ecosystem Tools
-
Section 41: More Practice and Review
-
Section 42: Final Practice and Mastery
-
Section 43: Ruby Interview Deep Dive
-
Section 44: Ruby Background Processing Deep Dive
-
Section 45: Ruby GraphQL
-
Section 46: Ruby Object Model Deep Dive
-
Section 47: Ruby Hanami Framework Overview
-
Section 48: Ruby gRPC and Protocol Buffers
-
Section 49: Ruby Data Processing
-
Section 50: Ruby Search Integration
-
Section 51: Ruby File Upload and Media
-
Section 52: Ruby Email and Notifications
-
Section 53: Ruby Admin Panels
-
Section 54: Ruby Feature Flags and Experimentation
-
Section 55: Ruby Monitoring and Observability
-
Section 56: Ruby Docker and Deployment Deep Dive
-
Section 57: Ruby Security Deep Dive
-
Section 58: More Advanced Metaprogramming
-
Section 59: More Final Projects
26: Overview of Rails vs Sinatra
You've spent the last few lessons mastering the Ruby language itself, but now we're getting to the part most people actually care about: putting that code on the web. When you look at the Ruby ecosystem, you're going to see two names pop up constantly: Sinatra and Ruby on Rails. I like to think of Sinatra as a scalpel and Rails as a fully equipped surgical suite. Both get the job done, but the experience of using them is night and day.
To show you what I mean, let's build a very simple "Quick-Note" app. The goal is basic: a page that lists a few notes and a way to add a new one. I'll walk you through how I'd approach this in both frameworks so you can feel the difference in "weight."
The lean approach with Sinatra
If I just need a couple of endpoints and don't want to deal with a massive folder structure, I go with Sinatra. It's a Domain Specific Language (DSL) that stays out of your way. Here is how I'd start the Quick-Note app:
require 'sinatra'
notes = ["Buy milk", "Finish Ruby course", "Call mom"]
get '/' do
erb :index, locals: { notes: notes }
end
post '/notes' do
notes << params[:note]
redirect '/'
end
In about ten lines of code, I've defined my data, my main page route, and the logic to handle a form submission. It's incredibly intuitive. You see a URL, you define a block of code, and that's it. No complex configuration, no magic hidden in five different directories.
Hitting a wall with Sinatra's minimalism
Here is where I usually trip up when I'm moving too fast. I ran the code above, but when I hit the page in my browser, I got a sinatra.erb: template not found error. I had written the Ruby logic, but I completely forgot that Sinatra expects a very specific folder structure for its views.
I had just put index.erb in the root folder. Sinatra doesn't look there; it looks for a folder specifically named views. I had to stop, create the directory, and move the file: mkdir views && mv index.erb views/. It's a small mistake, but it highlights the trade-off: Sinatra gives you freedom, but it doesn't hold your hand. You are responsible for the organization.
Scaling up with the Rails framework
Now, imagine this Quick-Note app needs a database, user accounts, password encryption, and an admin dashboard. If I stayed with Sinatra, I'd be spending my whole week manually installing gems and wiring them together. This is where Rails shines. Rails is built on "Convention over Configuration." It assumes there is a "right way" to do things, and if you follow its rules, it does the heavy lifting for you.
In Rails, I wouldn't just write a script; I'd generate a scaffold. One command—rails generate scaffold Note content:text—creates the database migration, the model, the controller, and the views. I don't have to worry about where the index.erb (or index.html.erb) goes because Rails has already decided that for me.
While the Sinatra version was one file, the Rails version is dozens of files. At first, that feels like overkill. But when you're working on a team, that structure is a godsend. Any Rails developer can jump into any Rails project and know exactly where the routes are defined and where the logic lives. In a large Sinatra app, every developer organizes things differently, which can lead to a total mess as the project grows.
Which one should you actually use?
I'll be honest: you'll use Rails more often in a professional setting because most companies are building complex, data-driven applications. However, don't sleep on Sinatra. It's perfect for building small APIs, internal tools, or "microservices" that only do one thing. If you can describe your app in one sentence (e.g., "It's a page that redirects links"), use Sinatra. If you describe it in a paragraph ("It's a marketplace where users can list items, message each other, and process payments"), use Rails.
📋 Practical Task
Build a Personal Quote Gallery with Sinatra
Your task is to create a minimal Sinatra application that displays a collection of your favorite quotes. You will need to practice the "lean" approach we discussed in the lesson.
- Create a directory for your project and a
viewsfolder inside it. - Create a file named
app.rb. In this file, define an array of strings containing at least three quotes. - Create a
GET /route that renders anindex.erbtemplate, passing the quotes array into the view. - In
index.erb, use a Ruby loop (like.each) to display each quote in an unordered list (<ul>). - Create a
POST /quotesroute that allows you to append a new quote to the array via a form submission, then redirects the user back to the home page.
Goal: Successfully run the app and add a new quote through the browser without encountering a "template not found" error.
There are no comments for now.