haml - don't use end tags

so I’m surprised I didn’t figure this out earlier… it was this message that finally drove the point home.

When using haml in your rails view templates, you do not need to close ruby blocks and conditional statements.

for example:

Here's how I was doing it before:

- content_for :head do
=   stylesheet_link_tag    'jquery.autocomplete'
=   javascript_include_tag 'jquery.autocomplete'
- end
- javascript_behaviour '$("input#user_full_name").autocomplete("project_roles/auto_complete_for_user_full_name")'

And here's how it really should be:

- content_for :head do
  = stylesheet_link_tag    'jquery.autocomplete'
  = javascript_include_tag 'jquery.autocomplete'
- javascript_behaviour '$("input#user_full_name").autocomplete("project_roles/auto_complete_for_user_full_name")'

So much nicer and readable, just as the haml gods intended :)

+1 for making ”- end” an error.

UPDATE:

On Oct 10, 2008, at 5:18 PM, Nathan Weizenbaum wrote: ”- end” actually is an error in the most recent Haml release, 2.0.3.

actionmailer ActionView ActiveRecord activesupport agile ajax alphadecimal audio autotest BDD blocks capistrano ssh ruby console controller css dashboard widget delegate dog puppy naming name DRM email obfuscation exceptions factories factories-and-workers factory pattern filemerge find and replace finder fink fixtures fun functional testing gem git google maps haml helper helpers imagemagick Intertrust irb javascript jquery jrails logo macro math meetup model openssl OS X patch Pioneer Electronics plugin polymorphism project management prototype.js rails rails gotcha rails,patch,validations railsconf rake rmagick RSA encryption ruby ruby on rails script scrum scrum lessons rails scrumninja shoulda subversion SyncTV TDD testing textmate tips tricks unique hashes unix shell validation view yaml zebra stripes