Rails 3: Validation error display using HAML

Here’s what I am using at the top of the view I just converted to HAML in a Rails 3 app to display any validation errors. Adjust for your own model and preferences as desired.

%h2 New Form in HAML
= form_for(@new_model) do |f|
  - if @new_model.errors.any?
    %div#errorExplanation
      %h2= "#{pluralize(@new_model.errors.count, "error")} prohibited this new_model from being saved:"
      %ul
        - @new_model.errors.full_messages.each do |msg|
          %li= msg

Edit 16-July-2010: It turns out that Rails 3 has a template engine that you can use to generate the views for you using HAML when you scaffold up a resource. Watch Ryan Bates’ excellent Railscast Episode 216 for more information.