Topics Covered in This Ruby on Rails Tutorial:
Building the complete Product Model, View, and Controller architecture, seamlessly incorporating professional designer HTML and CSS, integrating Bootstrap 4 with modern Webpacker tooling, and resolving common asset pipeline issues with images and fonts
Tutorial Learning Path
Foundation Setup
Create Rails application structure and establish basic configuration for the That Nutty Guy ecommerce site
Model-View-Controller
Build Product model with database migrations, create controllers with actions, and set up view templates
Design Integration
Convert static HTML designs into Rails application layout with proper templating and asset management
Asset Management
Resolve missing images, fonts, and styling issues by properly organizing assets in Rails directory structure
Exercise Overview
This comprehensive series of exercises demonstrates the complete development lifecycle of the That Nutty Guy ecommerce site that serves as our foundation in Exercise 8A. Consider this an intensive refresher that reinforces the core concepts from the first half of the book while introducing modern Rails 6 best practices.
You'll master the essential skills that define professional Rails development: architecting robust model objects, transforming static HTML designs into dynamic Ruby on Rails applications, implementing clean controller and view patterns, and establishing proper routing conventions. As a valuable bonus, you'll discover how to integrate Bootstrap 4 into Rails 6 using the modern Webpacker and Yarn ecosystem—essential skills for contemporary web development in 2026.
This hands-on approach mirrors real-world development scenarios where you'll frequently need to convert designer mockups into fully functional web applications while maintaining clean, maintainable code architecture.
This exercise series provides a comprehensive refresher of Rails fundamentals while introducing modern tools like Webpacker and Bootstrap 4 integration, building upon concepts from earlier coursework.
Getting Started
Launch your browser and navigate to the static HTML homepage provided by our designer: Desktop > Class Files > yourname-Rails Class > that nutty guy snippets > That Nutty Guy HTML > index.html.
Examine this professionally designed ecommerce homepage—this will become the foundation of our dynamic Rails application. Click on Tinfoil Hat to preview the product detail page structure. In this exercise, we'll build both the index and individual product pages with full functionality.
Open Applications > Utilities and launch Terminal.
In Terminal, type
cdfollowed by a single space (do NOT hit Return yet).On the Desktop, open the Class Files folder, then drag the yourname-Rails Class folder directly into the Terminal window to auto-complete the path.
Press Return in Terminal to navigate into that directory.
Generate your new Rails application with the following command:
rails new nuttyNOTE: Remember to press Return after each Terminal command unless explicitly instructed otherwise. This is standard practice we'll assume moving forward.
Rails has now scaffolded your complete application structure. Check the yourname-Rails Class folder—you'll find a new nutty directory containing your project foundation.
Open this new nutty folder in your preferred code editor (such as Sublime Text or VS Code) to enable efficient project navigation and file management throughout this tutorial.
Environment Setup Requirements
Review the designer's homepage and product detail templates before development
Use drag-and-drop method to ensure correct file path configuration
Initialize complete Rails directory structure and default configuration files
Establish development environment for efficient file management and editing
Creating the Product Model, View, & Controller
Now we'll build the core product architecture that powers our ecommerce functionality. This follows Rails' convention-over-configuration philosophy to create clean, maintainable code.
In your browser, open product.html from the That Nutty Guy HTML folder. This represents our target design for individual product pages. We'll implement both the Details and Specs tabs with full functionality.
Navigate into your Rails application directory by typing:
cd nuttyGenerate your Product model with appropriate attributes using this single command:
rails g model product title:string sku:string description:text specs:text price:decimalThis command creates several essential files: the model class, test files, and a database migration. Let's break down the syntax:
g: Rails shorthand for generateproduct: the model name (always singular in Rails conventions)title,sku,description,specs,price: the database fields with their respective data types
Open the generated migration file in your code editor: nutty > db > migrate > #_create_products.rb
NOTE: The timestamp number in the filename ensures proper migration ordering and will vary based on when you generated the file.
Locate line 8 and enhance the price field definition with precision controls:
t.decimal :price, precision: 8, scale: 2NOTE: This precision specification is crucial for financial data. Different database systems handle decimal precision inconsistently—some default to zero decimal places, which would store prices as whole dollars without cents. The
precision: 8parameter allows for 8 total digits, whilescale: 2reserves 2 digits for cents, enabling prices up to $999,999.99.Save and close the migration file.
Execute the migration to create your database structure:
rails db:migrateWith our database schema established, we'll create a seeds file to populate sample data. Seeds files are invaluable for development—they allow you to quickly populate your application with realistic test data, enabling immediate testing of features without manual data entry.
Navigate to the pre-prepared seeds file: Desktop > Class Files > yourname-Rails Level 2 Class > snippets folder.
Open seeds.rb in your code editor.
Select all content and copy it with Cmd–C, then close this file. We'll replace Rails' default seeds file with this customized version.
Open your project's seeds file: nutty > db > seeds.rb.
Delete all existing content and paste the new seed data.
Examine this code structure—you'll see an array of product objects, each containing the attributes we defined in our model. This demonstrates best practices for organizing seed data in a maintainable format.
Save and close the seeds file.
Populate your database with the sample products:
rails db:seedTerminal will display the eight products being created, confirming successful database population.
Now let's create the controller to manage these products. Generate the products controller:
rails g controller productsNOTE: Follow Rails naming conventions strictly—models use singular names (product), while controllers use plural names (products). This consistency is essential for Rails' auto-loading and routing mechanisms.
Configure your application routes in nutty > config > routes.rb
Remove all commented code, leaving only the basic structure:
Rails.application.routes.draw do endAdd your routing configuration:
Rails.application.routes.draw do resources :products, only: [:index, :show] root 'products#index' endSave and close the routes file.
Start your Rails development server:
rails sTest your routing by navigating to: localhost:3000
The error message "The action 'index' could not be found…" confirms that routing is functioning correctly—Rails is successfully finding the route but looking for the missing controller action.
Implement the controller actions in nutty > app > controllers > products_controller.rb
Add the index action to display all products:
class ProductsController < ApplicationController def index @products = Product.all end endThis creates an instance variable
@productscontaining all product records, making them available to the view template. This pattern mirrors our previous Flix application development.Add the show action for individual product pages:
class ProductsController < ApplicationController def index @products = Product.all end def show @product = Product.find(params[:id]) end endSave and close the controller file.
Create the index view template and save it as index.html.erb in nutty > app > views > products.
Create the show view template and save it as show.html.erb in the same nutty > app > views > products directory.
Rails follows strict naming conventions for automatic file resolution. These empty files establish the proper structure—Rails will automatically render them when the corresponding controller actions are called.
Verify your setup by navigating to localhost:3000 in your browser.
The blank page with "Nutty" in the browser title indicates successful configuration. No errors means your MVC architecture is properly connected and functional.
Product Model Architecture
Database Fields
Five core attributes: title, sku, description, specs, and price with proper data types including decimal precision configuration.
Migration Setup
Custom migration with price precision of 8 digits total and 2 decimal places to handle currency values correctly.
Sample Data
Seeds file containing eight pre-configured products to populate the development database for testing and demonstration.
Controller and Routing Configuration
Generate Controller
Create products controller with plural naming convention following Rails standards
Configure Routes
Set up resources for products with index and show actions, establish root route to products index
Controller Actions
Implement index action with Product.all and show action with Product.find using params[:id]
View Templates
Create index.html.erb and show.html.erb files with proper naming and location in views/products directory
Setting up the Site Design
With our Rails foundation established, we'll integrate the professional design assets and implement the templating system that separates reusable layouts from page-specific content.
Open the designer's HTML template: Desktop > Class Files > yourname-Rails Class > that nutty guy snippets > That Nutty Guy HTML > index.html
We'll extract the page template from this static HTML. In Rails' templating system, the application layout contains elements that persist across all pages (header, navigation, footer), while individual views contain page-specific content. This separation ensures maintainable, DRY (Don't Repeat Yourself) code.
Open your Rails layout file: nutty > app > views > layouts > application.html.erb
Copy these essential Rails helper tags (we'll need them shortly):
<%= csrf_meta_tags %> <%= csp_meta_tag %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>Create a temporary file and paste these Rails helpers for safekeeping.
Return to the index.html file and copy all its content.
In application.html.erb, replace all existing content with the copied HTML from index.html.
Retrieve the Rails helper tags from your temporary file, copy them, then close the temporary file without saving.
In application.html.erb, locate and replace these static CSS links (around lines 11–12):
Replace them with the Rails helper tags:
<%= csrf_meta_tags %> <%= csp_meta_tag %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>Reorder the helper tags to ensure proper Bootstrap integration. JavaScript must load before CSS for Webpacker compatibility:
<%= csrf_meta_tags %> <%= csp_meta_tag %> <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>Remove the outdated JavaScript includes at the bottom of the file (around lines 145–148):
Save the layout file.
Install Bootstrap and its dependencies using Yarn (the modern approach for Rails 6+ asset management):
yarn add bootstrap@4.3.1 jquery popper.jsConfigure Webpacker to load these libraries by opening app > javascript > packs > application.js
Add the following imports after the existing require statements:
require("jquery") import 'bootstrap' import './src/application.scss'Create the directory structure: app > javascript > packs > src
Create application.scss inside this src folder.
Add the Bootstrap import to application.scss:
@import '~bootstrap/scss/bootstrap';Configure Webpack to provide jQuery globally by updating config > webpack > environment.js:
const { environment } = require('@rails/webpacker') const webpack = require('webpack') environment.plugins.append('Provide', new webpack.ProvidePlugin({ $: 'jquery/src/jquery', jQuery: 'jquery/src/jquery', Popper: ['popper.js', 'default'] })) module.exports = environmentMinimize your code editor and navigate to the CSS assets: Desktop > Class Files > yourname-Rails Class > that nutty guy snippets > That Nutty Guy HTML > css
Copy normalize.min.css and main.css.
Navigate to your Rails stylesheets directory: Desktop > Class Files > yourname-Rails Class > nutty > app > assets > stylesheets
Paste both CSS files into this directory.
Open your application stylesheet: nutty > app > assets > stylesheets > application.css
Include normalize.css in the asset pipeline by adding it above the require_tree directive:
*= require 'normalize.min' *= require_tree . *= require_self */Save and close the file.
Test your progress by reloading localhost:3000 in your browser. The site should display improved styling, though images and some fonts will still be missing—we'll address these assets next.
Rails uses a templating approach where individual views represent page-specific content while the application layout contains fixed elements like headers, footers, and navigation that don't change across pages.
Bootstrap 4 Integration Process
Yarn Package Management
Install Bootstrap 4.3.1, jQuery, and Popper.js dependencies using Yarn for modern JavaScript package management in Rails 6.
Webpacker Configuration
Configure application.js with proper require statements and import Bootstrap styles through SCSS preprocessing for optimal loading.
Asset Pipeline Setup
Copy designer's CSS files to Rails assets directory and configure application.css to properly require normalize.min and other stylesheets.
Fixing the Missing Images & Fonts
The final step involves properly configuring static assets to ensure all images and custom fonts display correctly in your Rails application.
Open Finder and navigate to: Desktop > Class Files > yourname-Rails Class > that nutty guy snippets > That Nutty Guy HTML > img
Copy the entire img folder using Cmd–C.
Navigate to your Rails public directory: Desktop > Class Files > yourname-Rails Class > nutty > public
Paste the img folder using Cmd–V.
NOTE: Files in the public folder are served directly by the web server at the application root, making images accessible at URLs like localhost:3000/img/filename.jpg.
Refresh localhost:3000 in your browser.
Excellent! All images now display correctly. However, custom fonts like the "Nutty" logo font are still missing.
Return to Finder and navigate to: Desktop > Class Files > yourname-Rails Class > that nutty guy snippets > That Nutty Guy HTML > fonts
Copy the fonts folder using Cmd–C.
Paste it into the Rails public directory: Desktop > Class Files > yourname-Rails Class > nutty > public
The font paths in our CSS need adjustment for the Rails environment. Open: nutty > app > assets > stylesheets > main.css
Examine the font URL declarations at the top of the file. They contain
../relative path prefixes that worked for the static HTML but break in Rails.Use your editor's Find and Replace feature:
- Sublime Text: Go to Find > Replace
- Dreamweaver: Go to Edit > Find and Replace
Configure the replacement operation:
Find What: ../Replace With: /Execute Replace All. You should see 12 total replacements.
NOTE: This change converts relative paths to absolute paths from the application root, which aligns with how Rails serves public folder assets.
Save and close the CSS file.
Perform a final test by refreshing localhost:3000 in your browser.
Perfect! Your Rails application now displays the complete professional design with all images and custom fonts rendering correctly.
Keep both your code editor and Terminal open—you'll continue building on this foundation in the next exercise where we'll implement dynamic product listings and detailed product pages.
Asset Resolution Process
Image Assets
Copy img folder from HTML snippets to Rails public directory for root-level access
Font Integration
Copy fonts folder to public directory and update CSS path references for proper font loading
CSS Path Correction
Replace relative path references (../) with root references (/) using find and replace - 12 total replacements needed
Files in the public folder are served at the root of the site, so the img folder becomes accessible at localhost:3000/img. This is why relative path references need to be updated to absolute paths.