0
0
Ruby on Railsframework~30 mins

Convention over configuration principle in Ruby on Rails - Mini Project: Build & Apply

Choose your learning style9 modes available
Convention over Configuration Principle in Rails
📖 Scenario: You are building a simple blog application using Ruby on Rails. Rails follows the Convention over Configuration principle, which means it assumes certain defaults so you write less code. This project will help you see how Rails conventions reduce the need for extra setup.
🎯 Goal: Create a Rails model and controller using Rails naming conventions so that Rails automatically connects them without extra configuration.
📋 What You'll Learn
Create a Rails model named Article with attributes title and content
Create a controller named ArticlesController following Rails naming conventions
Use Rails default routing conventions for the ArticlesController
Use Rails conventions to render the default view without extra configuration
💡 Why This Matters
🌍 Real World
Most Rails applications rely on conventions to speed up development and reduce errors by following standard naming and file structure.
💼 Career
Understanding Rails conventions is essential for working efficiently on Rails projects and collaborating with other developers.
Progress0 / 4 steps
1
Create the Article model with attributes
Create a Rails model called Article with string attribute title and text attribute content using the Rails generator command.
Ruby on Rails
Need a hint?

Use the rails generate model command with the model name Article and attributes title:string and content:text.

2
Create the ArticlesController
Create a Rails controller named ArticlesController using the Rails generator command. This controller will follow Rails naming conventions automatically.
Ruby on Rails
Need a hint?

Use the rails generate controller command with the pluralized model name Articles.

3
Use Rails default routing for Articles
Add a resourceful route for articles in the config/routes.rb file using the Rails resources method to follow convention over configuration.
Ruby on Rails
Need a hint?

Open config/routes.rb and add resources :articles inside the Rails.application.routes.draw do ... end block.

4
Render the default view for ArticlesController#index
In the ArticlesController, add an index action that fetches all articles using @articles = Article.all. Rails will automatically render the index.html.erb view without extra configuration.
Ruby on Rails
Need a hint?

Define the index method inside ArticlesController and assign @articles = Article.all. Rails will use the default view app/views/articles/index.html.erb.