Rails Project Structure & MVC

Ruby on Rails is a full-stack web framework built on Ruby, and it organizes every app around the MVC pattern — Model, View, Controller — so your code has a clear, predictable home.

Learn Rails Project Structure & MVC in our free Ruby course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick…

Part of the free Ruby course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.

By the end of this lesson you'll create a new app with rails new, recognize the key folders, understand how a request flows through MVC, and start the server.

What You'll Learn in This Lesson

1️⃣ Creating an App and Starting the Server

Use rails new appname to scaffold a complete application, then rails server to run it. By default it listens on http://localhost:3000 .

Here are the most important folders Rails generates for you.

2️⃣ How MVC Fits Together

A request travels through four pieces: the router picks a controller action, the controller asks a model for data, and a view turns that data into HTML. Each part has a single, focused job.

Your turn. Match each file to its MVC role — Model, View, or Controller.

Walk through what happens when a user visits /posts , naming each step in order.

📋 Quick Reference — Rails Basics

Practice quiz

Which command creates a brand-new Rails application?

  • rails generate app
  • rails start blog
  • rails new blog
  • rails init blog

Answer: rails new blog. rails new blog scaffolds a complete new Rails application named blog.

In the MVC pattern, what is the Model responsible for?

  • Rendering HTML for the browser
  • Data and business logic (usually backed by the database)
  • Matching URLs to code
  • Styling the page with CSS

Answer: Data and business logic (usually backed by the database). The Model handles data and business rules, typically talking to the database via ActiveRecord.

Where does most of your day-to-day application code live?

  • The config/ directory
  • The db/ directory
  • The app/ directory
  • The test/ directory

Answer: The app/ directory. app/ holds models, views, controllers, helpers, and assets — the heart of the application.

Which subfolder of app/ holds your controller classes?

  • app/controllers
  • app/handlers
  • app/routes
  • app/logic

Answer: app/controllers. Controllers live in app/controllers, with files like posts_controller.rb.

What does 'convention over configuration' mean in Rails?

  • Every option must be configured by hand
  • Rails assumes sensible defaults so you write less setup code
  • Configuration files override all conventions
  • It forbids any configuration at all

Answer: Rails assumes sensible defaults so you write less setup code. Rails favors sensible defaults, so following conventions means little manual configuration.

Which command starts the local development web server?

  • rails build
  • rails deploy
  • rails console
  • rails server

Answer: rails server. rails server (or rails s) boots the development server, by default on port 3000.

In MVC, what is the Controller's main job?

  • Store rows in the database
  • Define the database schema
  • Receive requests, coordinate models, and choose a response
  • Hold the CSS and JavaScript

Answer: Receive requests, coordinate models, and choose a response. The Controller receives the request, works with models, and decides what view or redirect to return.

Which file defines the URL routes for a Rails app?

  • config/routes.rb
  • app/routes.rb
  • config/urls.rb
  • app/config/routes.yml

Answer: config/routes.rb. All routing rules live in config/routes.rb.

What is the typical flow of a request through MVC?

  • View, then Model, then Controller
  • Model, then View, then Controller
  • Router, then Controller, then Model, then View
  • Controller, then Router, then View

Answer: Controller, then Router, then View. A request hits the router, which dispatches to a controller; the controller uses models and renders a view.

Which directory holds database migrations and the schema?

  • lib/
  • public/
  • db/
  • vendor/

Answer: db/. db/ contains migrations, seeds, and schema.rb describing the database structure.