twitter-bootstrap-rails:加载样式表时出错 [英] twitter-bootstrap-rails: error loading stylesheets

查看:104
本文介绍了twitter-bootstrap-rails:加载样式表时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试第一次使用Twitter-bootstrap-rails gem,但遇到了一些问题.我删除了rails生成的所有样式表(application.css除外),然后运行了

I'm trying to use the Twitter-bootstrap-rails gem for the first time and I'm having some issues. I deleted all the stylesheets that rails generates except for application.css and I ran

rails g bootstrap:install less

获取bootstrap_and_overrides.css.less文件.根据文档,您需要在系统中要求bootstrap_和覆盖我做了的application.css.

to get the bootstrap_and_overrides.css.less file. According to the documentation you need to require bootstrap_and overrides in application.css which I did.

Application.css看起来像这样:

Application.css looks like this:

 *
 *= require_tree .
 *= require bootstrap_and_overrides.css.less
 *= require_self
 */

和bootstrap_and_overrides.css.less看起来像这样:

and bootstrap_and_overrides.css.less looks like this:

@import "twitter/bootstrap/bootstrap";
@import "twitter/bootstrap/responsive";

// bootstrap variables and mixins
@import "twitter/bootstrap/variables.less";
@import "twitter/bootstrap/mixins.less";

// other auto generated code below

问题是当我尝试运行该应用程序时遇到此错误:

The problem is that when I'm getting this error when I try to run the app:

NoMethodError in StaticPages#home
Showing /home/sheeka/Documents/workspace/my_projects/ruby/testapps/media_store/app/views/layouts/application.html.erb where line #5 raised:

undefined method `[]' for nil:NilClass

第5行指向

<%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>

当我删除application.css时,一切加载都没有问题,但是没有自举样式.任何帮助弄清楚这一点将不胜感激.

When I remove application.css everything loads with no problem but there's no bootstrap styling. Any help figuring this out would be much appreciated.

推荐答案

您是否尝试过禁用涡轮链接?据我了解,turbo-links与诸如base-rails gem和twitter-bootstrap gem之类的javascript库存在已知的兼容性问题.

Have you tried disabling turbo-links? From what I understand turbo-links has known compatibility issues with javascript libraries like the foundation-rails gem, and the twitter-bootstrap gem.

http://blog.steveklabnik. com/posts/2013-06-25-removing-turbolinks-from-rails-4

无论是否解决问题,我都会这样做,只是为了避免任何不必要的麻烦. (除非您绝对需要涡轮链接).

I would do that regardless of whether or not that fixes the problem, just to avoid any unnecessary hassle. (Unless you absolutely need turbolinks).

最后,我将使您的application.css文件看起来像这样:

Lastly, the I would have your application.css file look like this:

 *
 *= require_tree .
 *= require_self
 *= require bootstrap_and_overrides.css.less
 */

我认为在引导和覆盖之前,应该需要树和自我.当我不要求基础按正确的顺序加载到资产管道中时,也会遇到与基础相同的错误.对于资产管道,基本上的想法是,您始终希望当前控制器特定的样式表能够覆盖应用程序中的任何其他样式表. 我希望这最终对您有所帮助.当我收到此错误时,这对我有用.

I believe that tree and self should be required before bootstrap and overrides. I have gotten the same error thrown with foundation when I have not required it to load in the proper order in the asset pipeline. With the asset pipeline, basically the idea is that you always want the current controller specific stylesheet to be able to override whatever other stylesheets are in the app. I hope this ends up being helpful. This worked for me when I got this error.

http://guides.rubyonrails.org/asset_pipeline.html#清单文件和指令

这篇关于twitter-bootstrap-rails:加载样式表时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆