Route parameters
📖 Scenario: You are building a simple Rails app that shows details about books. Each book has a unique ID. You want to create a route that uses this ID in the URL to show the right book.
🎯 Goal: Build a Rails route that uses a route parameter called :id to capture the book's ID from the URL and pass it to the controller.
📋 What You'll Learn
Create a route with a parameter named
:id in config/routes.rbDefine a controller action
show in BooksControllerUse the route parameter
params[:id] inside the show actionAdd a view file to display the book ID
💡 Why This Matters
🌍 Real World
Web apps often show details for items like products, users, or posts by using route parameters in the URL.
💼 Career
Understanding route parameters is essential for building dynamic web pages and APIs in Rails development jobs.
Progress0 / 4 steps