How to add a new view to a Ruby on Rails Spree trading application?

A very simple question that I can’t solve is how to add a new view to my commercial Ruby on Rails Spree application. I want to make a link to a link next to the main link in _main_nav_bar.html.erb, and when you click it, you will see a page about where the products are displayed. So:

home about cart --------------------- things of the HOME page --------------------- footer 

Click on the link:

 home about cart --------------------- things of the ABOUT page --------------------- footer 

In the views / shared / _main_nav_bar.html.erb, the link I created (based on the home link) looks like this:

 <li id="home-link" data-hook><%= link_to Spree.t(:home), spree.root_path %></li> <li id="about-link" data-hook><%= link_to Spree.t(:about), spree.about %></li> 

The AboutController I created is as follows:

 module Spree class AboutController < Spree::StoreController def index end end end 

And finally, in config / routes.rb, I added the following code:

 root :about => 'about#index' 

When I try to start the server now, it just doesn't work anymore without causing an error message.

Can anyone help me with this issue? How to add a view and create a working link loaded in the main div?

EXTRA: routes.rb

 MyStore::Application.routes.draw do mount Spree::Core::Engine, :at => '/' Spree::Core::Engine.routes.prepend do #get 'user/spree_user/logout', :to => "spree/user_sessions#destroy" end get '/about' => 'spree/about#index' get '/contact' => 'spree/contact#index' end 
+6
source share
1 answer

You need to do in routes.rb :

 Spree::Core::Engine.routes.prepend do get '/about', :to => 'about#index', :as => :about end 

or without Spree::Core scope:

 get '/about', :to => 'spree/about#index', :as => :about 

Because you have about_controller.rb ie AboutController defined inside the Spree module. And therefore, you will need to reference the spree namespace on your route in order to properly set it up.

In your views:

 <li id="about-link" data-hook><%= link_to Spree.t(:about), spree.about_path %></li> 

or

 <li id="about-link" data-hook><%= link_to Spree.t(:about), main_app.about_path %></li> 
+5
source

All Articles