Thursday, August 16, 2012

Create HAML Hyperlinks In Sinatra

I spent an hour trying to figure out how to create a link, from one page to another, using haml in Sinatra. I found this solution in stackoverflow that worked for me.

Here is how my index.haml looks like...
  This website runs on Sinatra (a Ruby web framework) and HAML.
  It's going to be some sort of blog that I am going to update on a regular basis. Stay tuned!

  It is now 
  = time

  This link connects to the 
  %a{:href => '/contents'} table of contents
  table of contents.
  This is another link that goes to the <a href="/about">about</a> page.

There are two ways to create hyperlinks using HAML that I am now aware of:
  1. %a with all the whitespace, or,
  2. if I want to keep my code more compact and readable, I use the traditional a href way.
Here's how the web app looks now...
Click on the image to enlarge
Apparently, not all that is HAML is good. Compared to erb and other templating software that I have seen so far. Since HAML is flexible enough for me to use html tags, I am going to stick with HAML until something better comes along. Read this on your free time: Haml Sucks for Content -

EDIT... I tried using Rails' link_to, but couldn't make it to work. I am thinking that, if I can make a method with it, then I can use it somehow. I'll look into this in the future.

No comments:

Post a Comment