简体   繁体   English

twitter-bootstrap-rails:加载样式表时出错

[英]twitter-bootstrap-rails: error loading stylesheets

I'm trying to use the Twitter-bootstrap-rails gem for the first time and I'm having some issues. 我正在尝试第一次使用Twitter-bootstrap-rails gem,但遇到了一些问题。 I deleted all the stylesheets that rails generates except for application.css and I ran 我删除了rails生成的所有样式表(application.css除外),然后运行了

rails g bootstrap:install less

to get the bootstrap_and_overrides.css.less file. 获取bootstrap_and_overrides.css.less文件。 According to the documentation you need to require bootstrap_and overrides in application.css which I did. 根据文档,您需要在我执行的application.css中要求bootstrap_and覆盖。

Application.css looks like this: Application.css看起来像这样:

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

and bootstrap_and_overrides.css.less looks like this: bootstrap_and_overrides.css.less看起来像这样:

@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

and line 5 points to 第5行指向

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

When I remove application.css everything loads with no problem but there's no bootstrap styling. 当我删除application.css时,一切加载都没有问题,但是没有自举样式。 Any help figuring this out would be much appreciated. 任何帮助弄清楚这一点将不胜感激。

Have you tried disabling turbo-links? 您是否尝试过禁用Turbo链接? From what I understand turbo-links has known compatibility issues with javascript libraries like the foundation-rails gem, and the twitter-bootstrap gem. 据我了解,turbo-links与诸如base-rails gem和twitter-bootstrap gem之类的javascript库存在已知的兼容性问题。

http://blog.steveklabnik.com/posts/2013-06-25-removing-turbolinks-from-rails-4 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). (除非您绝对需要涡轮链接)。

Lastly, the I would have your application.css file look like this: 最后,我将让您的application.css文件如下所示:

 *
 *= 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#manifest-files-and-directives http://guides.rubyonrails.org/asset_pipeline.html#manifest-files-and-directives

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

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