Skip to content

Using HAML with Rails 3.2

By Paul Leader

I’m currently working on a small internal project, so I’m taking the opportunity to try out HAML and see if I like it.

After some digging around I found various docs that suggested that you need to add the haml gem and include something like the following in application.rb

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

However, after a couple of attempts to generate HAML templates for a scaffold controller there was clearly something not quite right. I kept getting the following error:

error  haml [not found]

It turns out that the haml gem doesn’t give you generators for Rails 3.

After a bit more digging I found the haml-rails gem. Add that to your Gemfile and it adds generators for HAML, and enables it, so you can get rid of that declaration in application.rb

So now I’m all HAML’d up and ready to go. I like it so far, but we’ll see how I feel in a week or two of working with it.