【问题标题】:Twitter bootstrap not working on railsTwitter bootstrap 无法在 Rails 上运行
【发布时间】:2016-08-24 23:21:51
【问题描述】:

我正在关注有关 twitter bootstrap basics 的截屏视频,以尝试更多地了解引导程序,但由于某种原因,当我转到 localhost 时,我的应用程序没有样式。

我也尝试了 github repo https://github.com/seyhunak/twitter-bootstrap-rails 中的步骤。

我也遵循了this SO post的指令,但是当我添加*= require bootstrap_and_overrides这一行时,它显示FileNotFound错误。

这是我在 Rails 新应用 bootstrap_practice 之后所做的:

rails g scaffold Product name price:decimal --skip-stylesheets
rake db:migrate
# added gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git' on gemfile (I have also tried just gem 'twitter-bootstrap-rails'
bundle install
rails g bootstrap:install

我检查了资产,它有必要的资产。

样式表 (application.css)

*
 *= require_tree .
 *= require_self
 */

JS:

//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
//= require turbolinks
//= require_tree .

最后,我的 application.html.erb 有

<%= csrf_meta_tags %>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>

我很确定这就是所需的一切。为什么我在 localhost 上的应用程序没有样式?

【问题讨论】:

  • 我更喜欢使用创作者的原创宝石:https://github.com/twbs/bootstrap-sass 它对我来说非常有用..
  • 超级基本的问题,但是twitter-bootstrap-rails gem 与bootstrap-sass gem 有什么区别?他们本质上是不是在做同样的事情(造型),但以前的宝石是“非官方”宝石吗?
  • 差异是使用 SASS 的官方 gem,但您使用的是 LESS。 SASS vs LESS

标签: ruby-on-rails twitter-bootstrap


【解决方案1】:

所以,我在 Rails 中以多种方式使用了 twitter-bootstrap,我最喜欢的是 bh gem。 Bootstrap Helpers在github上。

# Gemfile
gem 'bh'

# application.html.erb
<%= stylesheet_link_tag bootstrap_css %>
<%= stylesheet_link_tag font_awesome_css %>
<%= javascript_include_tag bootstrap_js %>

所有资产都通过 CDN 交付。

【讨论】:

  • 感谢您的意见!我会检查 bh-gem!
【解决方案2】:

自 railscasts 发布以来,官方 SASS 存储库已发布。 (Rails 自带 SASS。)

https://github.com/twbs/bootstrap-sass

seyhunak 的 repo 维护在 LESS 中,这也需要 therubyracer。

【讨论】:

  • 我刚刚注意到一个有LESS和另一个SASS,有什么区别?
  • 它们都是 CSS 预处理器。他们为 CSS 添加了许多特性,比如变量和 mixin。使用 SASS gem 可以让您通过覆盖 SASS 中的样式来自定义引导程序,而 LESS gem 将在 LESS 中做同样的事情。您将可以访问所有已定义的引导变量以进行自定义。就个人而言,我是 SASS 的粉丝。
猜你喜欢
  • 1970-01-01
  • 2012-05-31
  • 2011-10-26
  • 2011-12-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-01
相关资源
最近更新 更多