How to add new view to Ruby on Rails Spree commerce app?
ruby, ruby-on-rails, spree
Solution
You need to do in routes.rb:
Spree::Core::Engine.routes.prepend do
get '/about', :to => 'about#index', :as => :about
end
or without the `Spree::Core` scope:
get '/about', :to => 'spree/about#index', :as => :about
Because, you have your about_controller.rb i.e. `AboutController` defined inside `Spree` module. And, hence you'll have to reference the spree namespace in your route to set it properly.
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>
Problem
A very basic question that I cannot seem to solve is how to add a new view to my Ruby on Rails Spree commerce application. What I want to do is have a link next to the Home link in the _main_nav_bar.html.erb and when you click it have displayed an about page at the place where the products are displayed. So: ``` home about cart --------------------- things of the HOME page --------------------- footer ``` Click on about leads to: ``` home about cart --------------------- things of the ABOUT page --------------------- footer ``` In views/shared/_main_nav_bar.html.erb the link I created (based on the home link) looks as follows: ``` <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 looks 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 now try to start the server it just does not work anymore without giving an error message. Can someone please help me out on this issue? How do I add a view and create a working link that loads 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 ```