Skip to main content
Now that we’ve created a complete “Brand” model, let’s create an Admin Dashboard interface so our admins can manage the brands.

Step 1: Create the boilerplate Admin Dashboard UI

Admin Scaffold generator is a tool that helps us create a complete Admin Dashboard UI for our new resource. Run the following command in our Spree application root directory:
bin/rails g spree:admin:scaffold Spree::Brand
This will create the following files:
File TypePathDescription
Controllerapp/controllers/spree/admin/brands_controller.rbHandles the logic for the brands resource.
Viewapp/views/spree/admin/brands/index.html.erbHandles displaying the list of brands in the Admin Dashboard.
Viewapp/views/spree/admin/brands/new.html.erbHandles displaying the new brand form in the Admin Dashboard.
Viewapp/views/spree/admin/brands/edit.html.erbHandles displaying the edit brand form in the Admin Dashboard.
Partialapp/views/spree/admin/brands/_table_header.html.erbHandles displaying the table header in the brands index view.
Partialapp/views/spree/admin/brands/_table_row.html.erbHandles displaying the table row in the brands index view.
Partialapp/views/spree/admin/brands/_filters.html.erbHandles displaying the filters in the brands index view.
Partialapp/views/spree/admin/brands/_form.html.erbHandles displaying the form in the new and edit brand views.
It will also automatically add the following routes to your config/routes.rb file:
config/routes.rb
namespace :admin do
  resources :brands
end
You will now be able to access the brands resource at http://localhost:3000/admin/brands in your browser. To reference this route in your code, you can use the spree.admin_brands_path helper.

Step 2: Add Navigation Menu Item

Now that we’ve created a complete Admin Dashboard UI for the brand resource, let’s add a navigation menu item to the main sidebar so we can access it from the admin dashboard. Add the following to your config/initializers/spree.rb file:
config/initializers/spree.rb
Rails.application.config.after_initialize do
  # Add Brands to the admin sidebar
  sidebar_nav = Spree.admin.navigation.sidebar

  sidebar_nav.add :brands,
    label: :brands,
    url: :admin_brands_path,
    icon: 'award',
    position: 35,
    active: -> { controller_name == 'brands' },
    if: -> { can?(:manage, Spree::Brand) }
end
This will add a “Brands” link to the admin sidebar between Products (30) and Customers (40).

Adding to an Existing Submenu

To add “Brands” to the Products submenu instead add a new submenu item:
config/initializers/spree.rb
Rails.application.config.after_initialize do
  sidebar_nav = Spree.admin.navigation.sidebar

  # Add brands as a child of products
  sidebar_nav.add :brands,
    label: :brands,
    url: :admin_brands_path,
    position: 50,
    parent: :products,
    active: -> { controller_name == 'brands' },
    if: -> { can?(:manage, Spree::Brand) }
end
After restarting your server, you’ll see the new “Brands” navigation link in the admin sidebar!
For complete navigation API documentation including all available options, submenu creation, badges, and more, see the Admin Navigation guide.