问题描述
我刚刚将应用程序升级到最新版本的rails(3.1),并且希望集成Twitter的 Bootstrap 进入我的应用程序,但是它使用LESS而不是SASS,这是Rails 3.1默认使用的.
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.
如何配置Rails以使用Less而不是Sass?
How do I go about configuring Rails to use Less instead of Sass?
推荐答案
如呼吸暂停所指出的那样,Sprockets(Rails 3.1用于其资产管道的方式)支持LESS.
As apneadiving points out, Sprockets (what Rails 3.1 uses for its asset pipeline) supports LESS.
要配置Rails应用程序以支持LESS,可以将gem添加到Gemfile的资产组中:
To configure your Rails app to support LESS, you can add the gem to the assets group of your Gemfile:
group :assets do
gem 'less'
end
然后,运行bundle install
来获取less
gem及其依赖项(顺便说一下,其中包括libv8
gem,并且可能需要一段时间才能安装).
Then, run bundle install
to get the less
gem and its dependencies (which includes the libv8
gem, by the way, and can take awhile to install).
现在,只需在./app/assets/stylesheets
目录中的样式表中使用.css.less扩展名即可.请注意,如果您的LESS文件中有语法错误,您将收不到任何有用的消息(这使我绊了一秒钟).
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 App中使用更少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!