在 Rails 3.1 应用程序中使用 Less
我刚刚将我的应用程序升级到最新版本的 Rails (3.1),我想将 Twitter 的 Bootstrap 集成到我的应用程序中应用程序,但它使用 LESS 而不是 Rails 3.1 默认使用的 SASS。
我该如何配置 Rails 以使用 Less 而不是 Sass?
I've just upgraded my application to the latest release of rails (3.1) and I'm wanting to integrate Twitter's Bootstrap into my application but it uses LESS and not SASS which is what Rails 3.1 uses by default.
How do I go about configuring Rails to use Less instead of Sass?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如 apneadiving 指出的,Sprockets(Rails 3.1 用于其资产管道)支持 LESS。
要将 Rails 应用配置为支持 LESS,您可以将 gem 添加到 Gemfile 的资产组中:
然后,运行
bundle install
来获取less
gem 及其依赖项(顺便说一句,其中包括 libv8 gem,并且可能需要一段时间才能安装)。现在只需将 .css.less 扩展与
./app/assets/stylesheets
目录中的样式表一起使用即可。请注意,如果 LESS 文件中有任何语法错误,您将不会收到任何有用的消息(这让我困惑了一秒钟)。As apneadiving points out, Sprockets (what Rails 3.1 uses for its asset pipeline) supports LESS.
To configure your Rails app to support LESS, you can add the gem to the assets group of your Gemfile:
Then, run
bundle install
to get theless
gem and its dependencies (which includes thelibv8
gem, by the way, and can take awhile to install).Now it's just a matter of using the .css.less extension with the stylesheets in your
./app/assets/stylesheets
directory. Note that you won't get any helpful messages if you have any syntax errors in your LESS files (this tripped me up for a second).对于 Rails 3.1,我们现在有了 @metaskill 的 less-rails gem,它提供了特定于 Rails 的帮助程序等。它相当新,但似乎得到了积极维护。
您还可以使用 less-rails-bootstrap gem(由同一作者提供)来引入引导库。
另请参阅我的文章此处,了解如何在 Rails 上使用 Bootstrap 及其 mixin。
For Rails 3.1, we now have @metaskill's less-rails gem which provides helpers etc. specific to Rails. It is fairly new but seems to be actively maintained.
You can also use the less-rails-bootstrap gem (by the same author) to pull in the bootstrap libraries.
Also see my post here about using Bootstrap and its mixins on Rails.
非常直接,请参阅此处的原始文档:
Pretty straight, see original doc here: