简体   繁体   English

安装Bootstrap gem后,如何覆盖/更改Ruby on Rails Spree应用程序的布局?

[英]How to override/change lay-out of Ruby on Rails spree app after installing Bootstrap gem?

I have a Spree Commerce application with the spree_bootstrap gem installed by adding 我有一个通过安装spree_bootstrap gem的Spree Commerce应用程序

gem 'spree_bootstrap', github: 'jdutil/spree_bootstrap'

to the Gemfile. 到Gemfile。

Now on the main page I have all the familiar bootstrap divs as <div class="container row"> and <ul id="main-nav-bar" class="inline"> . 现在在主页上,我所有熟悉的引导div都为<div class="container row"><ul id="main-nav-bar" class="inline">

I am new to Rails and I want to change the lay-out masterpage by adding my own custom navbar and other tweaks. 我是Rails的新手,我想通过添加自己的自定义导航栏和其他调整来更改布局母版页。 Unfortunately application.html.rb is a virtually empty page and I don't think that is the one to make changes. 不幸的是,application.html.rb几乎是一个空页面,我认为那不是进行更改的页面。

My question is: how do I override or change the standard div values? 我的问题是:如何覆盖或更改标准div值? I do not have the files locally. 我没有本地文件。 I've heard about using Deface as a tool, but I don't know how to use it. 我听说过将Deface用作工具,但我不知道如何使用它。

I hope someone here can provide some more insight on changing the standard bootstrap Spree application. 我希望这里的人可以提供更多有关更改标准Bootstrap Spree应用程序的见解。

Create the file app/views/spree/layouts/spree_application.html.erb . 创建文件app/views/spree/layouts/spree_application.html.erb Copy and paste this content then edit as you wish :) 复制并粘贴内容,然后根据需要编辑:)

Repeat for any other Spree views and partials that you might want to restyle. 对其他任何您想重新设置样式的Spree视图和局部重复以上步骤。 If you'd like to know the paths you need to create & the content for a certain view or partial, check out the app/views/spree folder of their GitHub repo . 如果您想知道需要创建的路径以及某个视图或部分视图的内容,请查看其GitHub存储库中app/views/spree文件夹。

You might need to restart your server before seeing any changes. 在看到任何更改之前,您可能需要重新启动服务器。

First off, I think this question is duplicated in several other SO questions. 首先,我认为这个问题在其他几个SO问题中有所重复。 I did deal with this yesterday though, so I figured I would give an answer. 昨天我确实处理了这个问题,所以我想我会给出一个答案。

You should look at the deface gem (what Spree uses to allow you to override views). 您应该查看污损的宝石(Spree用于允许您覆盖视图的东西)。 Here's an example on how to replace the content of <ul id="main-nav-bar" class="inline"> , assuming the file is app/views/spree/shared/_nav_bar.html.erb . 这是一个有关如何替换 <ul id="main-nav-bar" class="inline">的内容的示例,假设文件是app/views/spree/shared/_nav_bar.html.erb Note that you have to find the file where the selector you're going to use actually is: 请注意,您必须找到要实际使用的选择器的文件:

# app/overrides/my_override.rb
Deface::Override.new(virtual_path: "spree/shared/nav_bar",
                     name: "my_navbar",
                     replace: "ul#main-nav-bar") do
  <<-HTML
  <nav class='navbar navbar-default navbar-fixed-top'>
    <div class='container'>
      ...
    </div>
  </nav>
  HTML
end

If you need more help you might want to take a look at their docs . 如果您需要更多帮助,则可能需要查看他们的文档 What is definitely not a good idea is to copy and paste the content of a gem to override. 绝对不是一个好主意,就是复制并粘贴gem的内容以覆盖。

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

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