【发布时间】:2014-02-01 12:43:52
【问题描述】:
我似乎无法解决的一个非常基本的问题是如何向我的 Ruby on Rails Spree 商务应用程序添加新视图。我想要做的是在 _main_nav_bar.html.erb 中的主页链接旁边有一个链接,当您单击它时,会在显示产品的位置显示一个关于页面。所以:
home about cart
---------------------
things of the HOME page
---------------------
footer
点击关于导致:
home about cart
---------------------
things of the ABOUT page
---------------------
footer
在 views/shared/_main_nav_bar.html.erb 中,我创建的链接(基于主页链接)如下所示:
<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>
我创建的 AboutController 如下所示:
module Spree
class AboutController < Spree::StoreController
def index
end
end
end
最后,我在 config/routes.rb 中添加了以下代码:
root :about => 'about#index'
当我现在尝试启动服务器时,它不再工作而没有给出错误消息。
有人可以帮我解决这个问题吗?如何添加视图并创建加载到主 div 中的工作链接?
额外: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
【问题讨论】:
-
在你的 routes.rb 中尝试:
root :about => 'spree/about#index' -
感谢您的帮助。我做到了,它说:
ArgumentError missing :controller Extracted source (around line #63): root :about => 'spree/about#index'我确实在 spree/about_controller.rb 中有控制器,我把它放在了帖子中。 -
应该是
root :to => 'spree/about#index'。对不起。 -
现在 routes.rb 中的代码看起来像这样:
root :to => 'home#index'root :about => 'spree/about#index'它给出了错误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. -
老兄,您不能在一个应用程序中拥有多个 root。要么这样做:
get '/about' => 'spree/about#index'你的情况。
标签: ruby-on-rails ruby spree