![](/img/trans.png)
[英]How to override a file that is causing trouble in Ruby on Rails Spree Commerce App?
[英]How to add new view to Ruby on Rails Spree commerce app?
我似乎無法解決的一個非常基本的問題是如何向我的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中加載的工作鏈接?
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
因為,你有你的about_controller.rb即在Spree
模塊中定義的AboutController
。 因此,您必須在路由中引用spree名稱空間以正確設置它。
在您的觀點中:
<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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.