【问题标题】:Trouble customizing Zurb Foundation with Rails使用 Rails 自定义 Zurb Foundation 时遇到问题
【发布时间】:2016-04-12 15:08:42
【问题描述】:

谈到 SCSS,我绝对是个新手。我需要一些帮助。

我在我的 Rails 4.2.4 项目中使用了 Zurb Foundation gem。我正在尝试进行一些全局自定义,例如更改 body-bg 颜色。我进入了 assets/stylesheets 文件夹中的foundation_and_overrides.scss 并取消了注释

$body-bg: $white;

希望将其更改为 $steel 或类似的。当我重新加载页面时,我得到 ​​p>

app/views/layouts/application.html.erb where line #7 raised:

Undefined variable: "$white".

application.html.erb 开始:

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><%= content_for?(:title) ? yield(:title) : "foodian" %></title>
    <meta name="description" content="<%= content_for?(:description) ?     yield(:description) : "Foodian" %>">
    <%= stylesheet_link_tag    "application" %>
    <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
    <%# Modernizr is required for Zurb Foundation %>
    <%= javascript_include_tag 'vendor/modernizr' %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
    <%= csrf_meta_tags %>

我确信我忽略了一些简单的事情。但我找不到任何“傻瓜”的例子。请帮忙。

application.css.scss

/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
 * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the bottom of the
 * compiled file so the styles you add here take precedence over styles defined in any styles
 * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
 * file per style scope.
 *
 *= require_tree .
 *= require_self
 */
/*= require foundation */
@import "foundation_and_overrides";

【问题讨论】:

    标签: ruby-on-rails sass zurb-foundation


    【解决方案1】:

    我的工作方式是将以下行添加到app/assets/stylesheets/application.scss,然后添加此行:

    @import "foundation_and_overrides";
    

    您还可以从同一文件中删除任何*= require foundation,因为foundation_and_overrides 已经导入了所需的文件。

    我不确定这是不是最好的方法,但它适用于 Foundation 5(我还没有尝试过 Foundation 6)。

    【讨论】:

    • 你能发布你的 application.scss 吗?我明天早上去看看,它对我有用。
    • 在上面添加了 applicatoin.css.scss
    • 问题是/*= require foundation */正在导入基础,没有注释掉...删除=符号或明确删除该行,它应该可以工作。
    • 那行得通。谢谢!我很困惑为什么 = 是个问题。 /* ... */ 不是被注释掉了吗?
    • 确实如此,但sprockets 会解析 cmets 以导入生成最终 CSS 和 JS 文件所需的文件。 *= 后面的内容由链轮解析。这允许 Rails 在生产中生成高效(和指纹)的单个 CSS 和 JS 文件。查看here了解更多详情。
    猜你喜欢
    • 2014-09-28
    • 1970-01-01
    • 1970-01-01
    • 2011-10-28
    • 2018-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多