问题
Currently, I have a Rails 3.2.9 Engine which is using sass-rails
. When I generate a controller with a couple actions, the assets are also generated (i.e., javascript and CSS). However, both the Javascript and SASS are *.js
and *.css
files. They're not CoffeeScript (*.js.coffee
) or SASS (*.css.sass
). Any ideas how to get this work?
回答1:
Here's a different solution which will use the coffee-rails
and sass-rails
gems by default - also fixes haml-rails
.
I added this to the top of my engine.rb
file:
require 'rails'
require 'coffee-rails'
require 'sass/rails'
require 'haml-rails'
What I did was inspect the source code of these files to see how they work in a normal Rails application. For example, in haml-rails
I looked at lib/haml-rails.rb and saw the following:
require 'haml'
require 'rails'
module Haml
module Rails
class Railtie < ::Rails::Railtie
if ::Rails.version.to_f >= 3.1
config.app_generators.template_engine :haml
else
config.generators.template_engine :haml
end
...
Similar files exist for sass-rails
(lib/sass/rails/railtie.rb) and coffee-rails
(lib/coffee/rails/engine.rb).
回答2:
Just append --stylesheet_engine=sass --javascript_engine=coffee
to your generator command (I'm assuming rails g controller
).
来源:https://stackoverflow.com/questions/13905389/how-to-use-sass-haml-and-coffeescript-in-rails-3-2-x-engine