Measurable Success «10 Checkpoints for Future-Proof Enterprise CMS» White Paper
Measurable Success - White Paper

Defining the Routing

Defining the Routing

Since we are combining two gems that both deliver content, we need to tweak the routing so that Scrivito's doesn't interfere with Solidus' and vice versa.

1. Adjust config/routes.rb to the following:

Rails.application.routes.draw do
  scrivito_route '/', using: 'homepage'
  scrivito_route '(/)(*slug-):id', using: 'slug_id'
  mount Spree::Core::Engine, :at => '/'
  scrivito_route '/*permalink', using: 'permalink', format: false

It is important to note that scrivito_route '/' needs to be placed before mount Spree::Core::Engine and scrivito_route '/*permalink' after mount Spree::Core::Engine.

Restart your Rails server and visit http://localhost:3000. You will now see the basic Scrivito homepage instead of the Solidus products page.

2. Make permalinks editable

To enable setting and changing the _permalink of a Page object, add the following to app/views/page/details.html.erb:

<%= scrivito_details_for "Permalink" do %>
  <%= scrivito_tag :div, @obj, :_permalink %>
<% end %>

3. Try it out

The routing causes any Scrivito Page with the permalink of a Solidus route to link directly to the Solidus page. Example for the /products route:

  • Add a new "Page" to the "Items of Welcome to Scrivito!" (the blue menu icon just under the home link)
  • Change the title of the new page to "Products"
  • Select “Edit page properties” from the page menu of the new page
  • Change “Permalink” to products

Now, clicking the “Products” navigation item lets you directly access Solidus' “Products” page.

4. Publish the latest changes.