Using Public and Assets Folders in Rails
📖 Scenario: You are building a simple Rails web app that needs to serve a custom logo image and a CSS file for styling. You will organize these files properly using the public and app/assets folders.
🎯 Goal: Create a Rails project structure where a logo image is placed in the public folder for direct access, and a CSS file is placed in the app/assets/stylesheets folder to style the homepage.
📋 What You'll Learn
Place a logo image file named
logo.png inside the public/images folderCreate a CSS file named
home.css inside app/assets/stylesheetsAdd a CSS rule in
home.css to set the background color of the body to #f0f0f0Reference the logo image in the homepage view using the correct path to the
public folderInclude the
home.css stylesheet in the homepage layout💡 Why This Matters
🌍 Real World
Web developers often need to organize images, stylesheets, and scripts properly in Rails projects to ensure efficient loading and maintainability.
💼 Career
Understanding the public and assets folders is essential for Rails developers to manage static files and styles, a common task in web development jobs.
Progress0 / 4 steps