The Archives


I’m Attending


Tag Archives: haml

How to Generate Views for Devise in HAML

Posted in: Programming by Steve on October 20, 2010

UPDATE (5/16/2011) – As Declan points out, this is no longer the case.  you can use the master of devise from github to get this functionality back.


I have been moving one of my sites to a rails application, and I am using the HAML view engine to make all my templates.  I am also using Devise as my authentication gem.  I am going to be doing some customizations of the views, however, by default, devise generates the views in ERB.

This is how to get the devise generator to use a HAML template instead of ERB.

Add the following to your GEMFILE:

gem 'haml'
group :development do
  gem 'hpricot'
  gem 'ruby_parser'

Then execute the following statements in a terminal/command window:

bundle install
rails generate devise:views -e haml

This will create the views for devise in HAML.

Using Other DOCTYPEs with HAML and Rails 3

Posted in: Programming by Steve on October 15, 2010

I recently purchased a site template from ThemeForest and I wanted to use it in a brand spankin’ new Rails 3 website.  I immediately created the application and installed haml.  I had heard so much about haml that I wanted to use it with this new site.  The DOCTYPE that the template used was 1.0 Transitional:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

However, by default, Rails 3 and haml render the default DOCTYPE as HTML5, like this:

!!! # => renders as <!DOCTYPE html>

Unfortunately, even if you try to add “!!! Transitional” as documented, it will not render the correct DOCTYPE.  So in order for me to get the correct doctype, I had to add a haml.rb configuration file under /config/initializers/ with the following code at the top of the file:

Haml::Template.options[:format] = :xhtml

So now, when the application is configured to use xhtml instead of the rails 3 default of html5, we will see the correct DOCTYPE. Took me a while to figure out why my template javascript and css wasn’t working properly.