Take the 2-minute tour ×

What is the difference between using view templates in Rails as '.html.haml' and as simply '.haml'? For example,

Are there any particular advantages of using one over the other? Or is one of them a standard practice? The same question goes for other types of templates as well, like '.erb'.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

The format matters when you're using Rails' automatic responders. See http://api.rubyonrails.org/classes/ActionController/MimeResponds.html#method-i-respond_with.

So for example, with:

class CarsController < ActionController::Base
  respond_to :html, :js

  def index
    respond_with Car.all

The app will render app/views/cars/index.html.erb and app/views/index.js.erb when viewing http://localhost:3000/cars and http://localhost:3000/cars.js, respectively.

Additionally, this is an established convention in Rails-land, so it's just a good idea to do this anyway, even if you're not using the auto-responders.

share|improve this answer
Does it mean that it is preferred and standard to use '.html.haml' instead of using '.haml'? –  Vignesh Feb 1 '12 at 12:18
I understand using explicit format might be necessary when using auto-responders other than for html format. –  Vignesh Feb 1 '12 at 12:42
Yes, '.html.haml' would be the preferred standard. –  jtrim Feb 2 '12 at 5:46

Your Answer


