简体   繁体   English

如何在Ruby on Rails狂欢商务应用程序中添加新视图?

[英]How to add new view to Ruby on Rails Spree commerce app?

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. 我似乎无法解决的一个非常基本的问题是如何向我的Ruby on Rails Spree商务应用程序添加新视图。 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. 我想要做的是在_main_nav_bar.html.erb的主页链接旁边有一个链接,当你点击它时,在显示产品的地方显示了一个关于页面的信息。 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: 在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>

The AboutController I created looks as follows: 我创建的AboutController看起来如下:

module Spree
  class AboutController < Spree::StoreController

    def index

    end
  end
end

And finally, in config/routes.rb I added the following code: 最后,在config / routes.rb中,我添加了以下代码:

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? 如何添加视图并创建在主div中加载的工作链接?

EXTRA: 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

You need to do in routes.rb : 你需要在routes.rb中做:

Spree::Core::Engine.routes.prepend do
  get '/about', :to => 'about#index', :as => :about
end

or without the Spree::Core scope: 或没有Spree::Core范围:

get '/about', :to => 'spree/about#index', :as => :about

Because, you have your about_controller.rb ie AboutController defined inside Spree module. 因为,你有你的about_controller.rb即在Spree模块中定义的AboutController And, hence you'll have to reference the spree namespace in your route to set it properly. 因此,您必须在路由中引用spree名称空间以正确设置它。

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM