This guide assumes you’ve completed the Model, Admin, Rich Text, File Uploads, and Extending Core Models tutorials. You should have a working
Spree::Brand model with products associated to brands.What We’re Building
By the end of this tutorial, you’ll have:- A custom theme for your store
- A brands listing page at
/brands - Individual brand pages at
/brands/:id - Styled views using Tailwind CSS
Step 1: Create a Custom Theme
Before adding custom views, create your own theme. This is important because:- Upgrade safety - Your customizations won’t be overwritten when updating Spree
- Clean separation - Your code stays separate from Spree’s default theme
- Full control - You get a complete copy of all templates to customize
app/views/themes/my_store/- Copy of all storefront templatesapp/models/spree/themes/my_store.rb- Theme configuration class
config/initializers/spree.rb:
config/initializers/spree.rb
Activate Your Theme
- Go to Admin → Storefront → Themes
- Find your new theme in the “Add new theme” section
- Click Add to activate it
Step 2: Add Routes
Now let’s add routes for our brand pages. Create or update your routes file:config/routes.rb
The
scope '(:locale)' wrapper enables internationalization - URLs like /fr/brands will work automatically if you have French locale enabled.Step 3: Create the Controller
Create a controller that inherits fromSpree::StoreController. This base controller provides:
- Access to
current_store,current_theme,current_currency - User authentication helpers
- Storefront layout and helpers
- SEO and meta tag support
app/controllers/spree/brands_controller.rb
Key Points
- Inherit from
Spree::StoreController- NotApplicationController. This gives you access to all storefront functionality. - Use
current_store- Always scope queries to the current store for multi-store support. - Override
accurate_title- This sets the page<title>tag.
Step 4: Create the Views
Storefront views live in your theme directory. Create the brands views in your custom theme:Brands Listing Page
app/views/themes/my_store/spree/brands/index.html.erb
Brand Card Partial
app/views/themes/my_store/spree/brands/_brand_card.html.erb
Single Brand Page
app/views/themes/my_store/spree/brands/show.html.erb
Step 5: Add Translations
Add the necessary translations:config/locales/en.yml
Step 6: Add Navigation Link (Optional)
To add a link to brands in your header navigation, you can use the Admin Dashboard:- Go to Storefront → Theme Editor
- Click on Header section
- Add a new navigation link pointing to
/brands
Understanding the View Structure
Theme Directory
Views are organized by theme inapp/views/themes/{theme_name}/spree/:
Spree looks for views in your active theme first. If a view isn’t found, it falls back to the default theme. This means you only need to copy and customize the files you want to change.
Key CSS Classes
Spree’s default theme uses these common patterns:| Class | Purpose |
|---|---|
page-container | Centered container with max-width and padding |
bg-accent | Uses theme’s accent background color |
text-primary | Uses theme’s primary text color |
btn-primary | Primary button style |
btn-secondary | Secondary button style |
Using Spree Helpers
Testing Your Pages
Start your Rails server and visit:http://localhost:3000/brands- Brand listinghttp://localhost:3000/brands/1- Single brand (using the brand’s ID)
What’s Next?
You now have working brand pages using standard Rails MVC patterns. In the next guide, Testing, we’ll write automated tests for your feature to make sure it works as expected, also in the future when you make changes to your code.Complete Controller Example
Here’s the complete controller with all features:app/controllers/spree/brands_controller.rb
To use SEO-friendly slugs like
/brands/nike instead of /brands/1, follow the SEO tutorial.Related Documentation
- Storefront Overview - Storefront architecture
- Custom CSS - Styling with Tailwind
- Helper Methods - Available helpers

