如何向 Ruby on Rails Spree 商务应用程序添加新视图? [英] How to add new view to Ruby on Rails Spree commerce app?
问题描述
一个我似乎无法解决的非常基本的问题是如何向我的 Ruby on Rails Spree 商务应用程序添加新视图.我想要做的是在_main_nav_bar.html.erb 中的主页链接旁边有一个链接,当您单击它时,会在显示产品的地方显示一个关于页面.所以:
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
点击关于线索:
home about cart
---------------------
things of the ABOUT page
---------------------
footer
在 views/shared/_main_nav_bar.html.erb 中,我创建的链接(基于主页链接)如下所示:
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>
我创建的 AboutController 如下所示:
The AboutController I created looks as follows:
module Spree
class AboutController < Spree::StoreController
def index
end
end
end
最后,在 config/routes.rb 中,我添加了以下代码:
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.
有人可以帮我解决这个问题吗?如何添加视图并创建可在主 div 中加载的工作链接?
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?
额外:routes.rb
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
推荐答案
你需要在routes.rb中做:
Spree::Core::Engine.routes.prepend do
get '/about', :to => 'about#index', :as => :about
end
或没有 Spree::Core
作用域:
get '/about', :to => 'spree/about#index', :as => :about
因为,您在 Spree
模块中定义了 about_controller.rb,即 AboutController
.并且,因此您必须在路由中引用 spree 命名空间以正确设置它.
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.
在您看来:
<li id="about-link" data-hook><%= link_to Spree.t(:about), spree.about_path %></li>
或
<li id="about-link" data-hook><%= link_to Spree.t(:about), main_app.about_path %></li>
这篇关于如何向 Ruby on Rails Spree 商务应用程序添加新视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!