English 中文(简体)
How to make Rails 3.1 use SASS (Over SCSS) as the default?
原标题:

Having a hard time figuring out how to make SASS, not SCSS, as the default for stylesheets.

I ve tried making a sass_config.rb file with this:

Sass::Plugin.options[:syntax] = :sass
Sass::Plugin.options[:style] = :compressed

I ve also tried adding that to the environment.rb file. Either way I get this error:

.../config/environment.rb:7:in `<top (required)> : 
  uninitialized constant Sass::Plugin (NameError)
最佳回答

For rails 3.1.rc4, you could set the config:

config.sass.preferred_syntax = :sass

in the application.rb file

问题回答

I added the following to config/environments/development.rb:

config.sass.preferred_syntax = :sass

That did the trick.

Do require sass/plugin and make sure it s at the bottom after your Application.initialize! call.

I definitely prefer sass to scss too - have you considered just using the compass gem for all your CSS, and adding preferred_syntax = :sass to config/compass.rb

I haven t tested this out yet on rails 3.1 yet but it works in 3.0.7

EDIT

As a troubleshooting step, what happens when you remove just the first line of code from sass_config.rb so that it just has the second one? Do both these lines cause the error?

As @krainboltgreene commented, adding the following line to config/application.rb

config.generators.stylesheet_engine = :sass

makes sass the default format for stylesheet generators. However, since Rails 3.1.beta1 doesn t support it, one gets the following error messages

$ rails g scaffold user name:string
...
Could not find "scaffold.css.sass" in any of your source paths. Your current source paths are:
.../gems/railties-3.1.0.beta1/lib/rails/generators/rails/scaffold/templates
...

$ rails g controller users
...
Could not find "stylesheet.css.sass" in any of your source paths. Your current source paths are: 
.../gems/railties-3.1.0.beta1/lib/rails/generators/rails/assets/templates

As you see, one cannot change the default format without breaking the generators. Instead, you can manually create extra *.css.sass files, which are working fine with or without scss ones.

I found this answer somewhere else, can t remember exactly, but put this in config/initializers/sass.rb:

Sass::Engine::DEFAULT_OPTIONS[:load_paths].tap do |load_paths|
  load_paths << "#{Rails.root}/app/assets/stylesheets"
  load_paths << "#{Gem.loaded_specs[ compass ].full_gem_path}/frameworks/compass/stylesheets"
end

I also prefer SASS syntax (to SCSS). All you have to do is name files mystylesheet.css.sass instead and it just works. You can even rename your application.css to application.css.sass, change the comments at the top to // instead of /* */ and use the require_* directives—it all works, and then you can use SASS in your application global stylesheet. It won t if you use compass in app/stylesheets.

Don t require the Sass::Plugin, it s totally separate to the new Rails asset engine which is based on Sprockets. It already knows how to compile SASS for you and manages the bundling of assets properly.

I imagine a new Compass release will do this automatically for Rails 3.1+ projects using the asset pipeline.





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签