Is there a way to configure rails to use haml by default, i.e. when a scaffold is generated the according scaffold_name/index.html.haml is generated instead of scaffold_name/index.html.erb.

Similar to how you are able to add config.sass.preferred_syntax = :sass to config/application.rb and have scaffold_name.sass generated by default.

Tried adding the following to config/application.rb

config.generators do |g| 
  g.template_engine :haml
end

but ened up with the following

$ rails generate scaffold foo name:string
  invoke  active_record
  create    db/migrate/20120208152550_create_foos.rb
  create    app/models/foo.rb
  invoke    test_unit
  create      test/unit/foo_test.rb
  create      test/fixtures/foos.yml
   route  resources :foos
  invoke  scaffold_controller
  create    app/controllers/foos_controller.rb
   error    haml [not found]
  invoke    test_unit
  create      test/functional/foos_controller_test.rb
  invoke    helper
  create      app/helpers/foos_helper.rb
  invoke      test_unit
  create        test/unit/helpers/foos_helper_test.rb
  invoke  assets
  invoke    coffee
  create      app/assets/javascripts/foos.js.coffee
  invoke    sass
  create      app/assets/stylesheets/foos.css.sass
  invoke  sass
  identical    app/assets/stylesheets/scaffolds.css.sass
$ rails destroy scaffold foo                                                                                                                        
  invoke  active_record
  remove    db/migrate/20120208152550_create_foos.rb
  remove    app/models/foo.rb
  invoke    test_unit
  remove      test/unit/foo_test.rb
  remove      test/fixtures/foos.yml
   route  resources :foos
  invoke  scaffold_controller
  remove    app/controllers/foos_controller.rb
   error    haml [not found]
  invoke    test_unit
  remove      test/functional/foos_controller_test.rb
  invoke    helper
  remove      app/helpers/foos_helper.rb
  invoke      test_unit
  remove        test/unit/helpers/foos_helper_test.rb
  invoke  assets
  invoke    coffee
  remove      app/assets/javascripts/foos.js.coffee
  invoke    sass
  remove      app/assets/stylesheets/foos.css.sass
  invoke  sass

I created a nice little bundle command to replace all erb with haml files following this screencast but I'm still interested in making it default when the scaffold is created! How do I make it so haml files (not erb!) are generated by default?


I use gem 'haml-rails', '= 0.3.4' in my gemfile. it automatically generates *.html.haml without any configuration.


In your application config, try setting the following:

config.generators do |g|
  g.template_engine :haml
end

if you have gem 'haml-rails' in your Gemfile it should create haml files by default instead of erb.