Here's an excerpt from haml FAQ:
Why is my markup indented properly in development mode, but not in production?
To improve performance, Haml defaults to {Haml::Options#ugly "ugly" mode} in Rails apps running in production.
Link to FAQ itself. To fix this issue, you need to provide Haml with a different option. So, you basically need to implement an initializer with correct setting:
# config/initializers/haml.rb
Haml::Template.options[:ugly] = false
Haml::Template.options[:remove_whitespace] = false
Here's a link to other examples.
List of available options can be found here.