Web Developer in Ruby on Rails and CakePHP
RSS icon Email icon Home icon
  • HAML + Javascript

    Posted on October 20th, 2009 5 comments

    I am very meticulous when it comes to server calls. In most of my Rails applications, I make sure to only specify those Javascript files that are deemed absolute necessary for any given view so as to not clutter things with wasted bytes of memory.

    While I was playing around with HAML, I needed to insert a very simple, very specific jQuery function. As of this writing, a simple Google search of “haml and javascript” came up with some old and unhelpful results. The official HAML documentation was, of course, among those results, but the answer was at the bottom of the document and a quick scan of the table of contents didn’t associate “Filters :” as being the correct the section.

    Of course, a blog or two and the HAML google group already tackled the topic, so I’m just going to regurgitate in order in hopes that next person with this problem will find the answer in 2 minutes instead of my 10 minutes.

    An example:

    :javascript
      $(function() {
        $("#tabs").tabs();
      });
    

    No related posts.

     

    5 responses to “HAML + Javascript”

    1. Hey Chris,

      What did you search on Google for? I just did a search for “haml and javascript” as well as “haml javascript” and they both showed the two blog posts you mentioned.

      PS: Thanks for the mention.

      Melvin Ram
      RailsNotes.com

    2. Melvin: Thanks for writing such a great post on your blog about the topic!

      This post was more to proliferate the answer to the question of getting HAML and Javascript working together. Since it took me longer than I wanted it to, I figured others may have the same problem.

    3. I’ll have all the filters show up in the table of contents in the next minor release of the reference.

    4. Do you know of a textmate haml bundle that will recognize and syntax highlight this embedded javascript?

    5. Just found one!!
      http://github.com/quackingduck/ruby-haml.tmbundle

    Leave a reply