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
root :about => 'spree/about#index'
in your routes.rb – GreenhornArgumentError 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. – Majormajordomoroot :to => 'spree/about#index'
. Sorry. – Greenhornroot :to => 'home#index'
root :about => 'spree/about#index'
and it gives the errorArgumentError 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.
– Majormajordomoget '/about' => 'spree/about#index'
for your case. – GreenhornArgumenterror missing :controller Extracted source (around line #63): root :to => 'home#index' get :about => 'spree/about#index'
. – Majormajordomoget '/about' => 'spree/about#index'
and the server starts again without errors! Thanks! The link does not work though. I have<li id="about-link" data-hook><%= link_to Spree.t(:about), spree.root_path%></li>
, so naturally it links tospree.root_path
still? How do I make this link go to /about? – Majormajordomoget '/about' => 'spree/about#index', :as => :about
in routes.rb and in link(view template):<li id="about-link" data-hook><%= link_to Spree.t(:about), about_path%></li>
. this should work. – Greenhornabout_path is undefined
. Where do I define these variables? – Majormajordomoget '/about' => 'spree/about#index', :as => :about
in your routes.rb? – Greenhorn<li id="about-link" data-hook><%= link_to Spree.t(:about), about_path%></li>
should work. otherwise try with:spree.about_path
instead ofabout_path
– Greenhornundefined method about_path for #<ActionDispatch::Routing::RoutesProxy:0xc8008d4>
when I dospree.about_path
or onlyabout_path
. Do I need to map thisabout_path
to /about somewhere? – Majormajordomoget '/about' ..
with in a block or may be helper isn't being set properly. if not then Do:rake routes|grep about
in terminal(by cd to your app's directory) and post the output. – Greenhornrake routes|grep about
isabout GET /about(.:format) spree/about#index
– Majormajordomo