📖 Scenario: Imagine you want to build a website that helps people share their favorite recipes. You want it to be fast to build and easy to change later.
🎯 Goal: You will create a simple Ruby on Rails project that shows why Rails exists by setting up a basic data structure, adding a configuration, applying core Rails logic, and completing the setup to display a list of recipes.
📋 What You'll Learn
Create a Ruby hash called recipes with exact recipe names and descriptions
Add a configuration variable called show_descriptions set to true
Use a Rails view loop to display recipe names and descriptions only if show_descriptions is true
Complete the Rails view with proper HTML structure and Rails tags
💡 Why This Matters
🌍 Real World
Ruby on Rails helps developers build websites quickly by providing ready tools to handle data, views, and user interaction in a clean way.
💼 Career
Understanding why Rails exists and how to use its core features is essential for web developers working with Ruby on Rails to build maintainable and fast web applications.
Progress0 / 4 steps
1
DATA SETUP: Create the recipes hash
Create a Ruby hash called recipes with these exact entries: 'Pancakes' => 'Fluffy and light', 'Spaghetti' => 'Classic Italian pasta', and 'Salad' => 'Fresh and healthy'.
Ruby on Rails
Hint
Use a Ruby hash with string keys and string values exactly as shown.
2
CONFIGURATION: Add a show_descriptions variable
Add a Ruby variable called show_descriptions and set it to true.
Ruby on Rails
Hint
Just create a variable named show_descriptions and assign it the value true.
3
CORE LOGIC: Use a Rails view loop to display recipes
In a Rails view file, use recipes.each do |name, description| to loop through the recipes. Inside the loop, display the name in an <h2> tag. If show_descriptions is true, display the description in a <p> tag.
Ruby on Rails
Hint
Use ERB tags to loop and conditionally display descriptions.
4
COMPLETION: Wrap the view in a proper HTML structure
Add a <section> tag around the recipes loop and include a <header> with <h1>Recipe List</h1> above the loop.
Ruby on Rails
Hint
Wrap the loop inside semantic HTML tags for better structure and accessibility.
Practice
(1/5)
1. Why was Ruby on Rails created? Rails helps developers by:
easy
A. Forcing developers to write all code manually
B. Providing tools to build web apps faster and easier
C. Replacing the need for databases in web apps
D. Making Ruby code run faster than other languages
Solution
Step 1: Understand Rails purpose
Rails was designed to speed up web app development by giving ready-made tools and structure.
Step 2: Evaluate options
Only Providing tools to build web apps faster and easier matches this goal. Options A, B, and C are incorrect because Rails does not force manual coding, does not make Ruby faster, and does not replace databases.
Final Answer:
Providing tools to build web apps faster and easier -> Option B
Quick Check:
Rails helps build apps faster = D [OK]
Hint: Rails is about speed and ease in web development [OK]
Common Mistakes:
Thinking Rails makes Ruby faster
Believing Rails removes databases
Assuming Rails requires manual coding
2. Which of these is a correct way to start a new Rails project in the terminal?
easy
A. rails new myapp
B. ruby create myapp
C. rails start myapp
D. ruby new project myapp
Solution
Step 1: Recall Rails project creation command
The standard command to create a new Rails app is rails new appname.
Step 2: Check options
Only rails new myapp matches the correct syntax. Others use wrong commands or order.
Final Answer:
rails new myapp -> Option A
Quick Check:
rails new appname = A [OK]
Hint: Remember: 'rails new' starts a new project [OK]
Common Mistakes:
Using 'ruby' instead of 'rails' to create projects
Mixing command order
Using 'start' instead of 'new'
3. What will happen when you run rails server in a Rails project folder?
medium
A. It installs Ruby on your computer
B. It deletes the project files
C. It starts a web server to run your app locally
D. It opens a database management tool
Solution
Step 1: Understand 'rails server' command
This command launches a local web server so you can see and test your app in a browser.
Step 2: Evaluate options
Only It starts a web server to run your app locally describes this behavior. Others describe unrelated or incorrect actions.
Final Answer:
It starts a web server to run your app locally -> Option C
Quick Check:
rails server runs local web server = C [OK]
Hint: 'rails server' runs your app locally in browser [OK]
Common Mistakes:
Thinking it deletes files
Confusing it with Ruby installation
Assuming it opens database tools
4. You wrote rails new myapp but got an error: command not found: rails. What is the likely problem?
medium
A. The folder 'myapp' already exists
B. You typed the command correctly but your computer is off
C. You need to use ruby new myapp instead
D. Rails gem is not installed or not in your PATH
Solution
Step 1: Analyze the error message
'command not found: rails' means the system cannot find the Rails command, usually because Rails is not installed or not set in PATH.
Step 2: Check options
Rails gem is not installed or not in your PATH correctly identifies the cause. You typed the command correctly but your computer is off is unrelated to command errors. You need to use ruby new myapp instead is wrong syntax. The folder 'myapp' already exists would cause a different error.
Final Answer:
Rails gem is not installed or not in your PATH -> Option D
Quick Check:
Command not found means Rails missing = A [OK]
Hint: Command not found means Rails not installed or PATH missing [OK]
Common Mistakes:
Assuming computer power off causes command errors
Using wrong command syntax
Confusing folder existence with command errors
5. Which of these best explains why Rails encourages 'convention over configuration'?
hard
A. It reduces the need to write extra setup code by following standard rules
B. It forces developers to configure every detail manually
C. It disables default settings to avoid confusion
D. It requires using only one database type
Solution
Step 1: Understand 'convention over configuration'
This principle means Rails provides default ways to do things so developers write less setup code.
Step 2: Evaluate options
It reduces the need to write extra setup code by following standard rules correctly explains this. Options A, C, and D contradict the idea or are unrelated.
Final Answer:
It reduces the need to write extra setup code by following standard rules -> Option A
Quick Check:
Convention means less config code = B [OK]
Hint: Convention means Rails sets defaults to save coding time [OK]
Common Mistakes:
Thinking Rails forces manual config
Believing defaults are disabled
Assuming Rails limits database choices
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.