6

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
user2609980
  • 10,264
  • 15
  • 74
  • 143
  • try: `root :about => 'spree/about#index'` in your routes.rb – Surya Feb 01 '14 at 12:50
  • Thanks for your help. I did and it says: `ArgumentError missing :controller Extracted source (around line #63): root :about => 'spree/about#index'` I do have the controller in spree/about_controller.rb which I placed in the post. – user2609980 Feb 01 '14 at 12:53
  • it should be `root :to => 'spree/about#index'`. Sorry. – Surya Feb 01 '14 at 12:57
  • Now the code in routes.rb looks like this: `root :to => 'home#index'` `root :about => 'spree/about#index'` and it gives the error `ArgumentError Invalid route name, already in use: 'root' You may have defined two routes with the same name using the :as option, or you may be overriding a route already defined by a resource with the same naming.` – user2609980 Feb 01 '14 at 13:06
  • Dude, you can't have multiple **root** in one application. Either do this: `get '/about' => 'spree/about#index'` for your case. – Surya Feb 01 '14 at 13:07
  • Okay seems logical, when I do get it says it cannot find the controller again. Message: `Argumenterror missing :controller Extracted source (around line #63): root :to => 'home#index' get :about => 'spree/about#index'`. – user2609980 Feb 01 '14 at 13:11
  • Did you try what I wrote? Does it work? – Surya Feb 01 '14 at 13:13
  • I updated the routes.rb with the `get '/about' => 'spree/about#index'` and the server starts again without errors! Thanks! The link does not work though. I have `
  • `, so naturally it links to `spree.root_path` still? How do I make this link go to /about? – user2609980 Feb 01 '14 at 13:15
  • You're new to spree, I suppose? Do: `get '/about' => 'spree/about#index', :as => :about` in routes.rb and in link(view template): `
  • `. this should work. – Surya Feb 01 '14 at 13:17
  • Yes quite new! :) For now: `about_path is undefined`. Where do I define these variables? – user2609980 Feb 01 '14 at 13:26
  • I am sorry, I am naive. Pardon me. Did you do: `get '/about' => 'spree/about#index', :as => :about` in your **routes.rb**? – Surya Feb 01 '14 at 13:27
  • Yes. And now the localhost:3000/about links correctly to the about.html.erb page I made in views/about/index.html.erb. The only issue is how to make the link in the _main_nav_bar.html.erb. Then we are there ;-). – user2609980 Feb 01 '14 at 13:34
  • link: `
  • ` should work. otherwise try with: `spree.about_path` instead of `about_path` – Surya Feb 01 '14 at 13:35