Adventures with Ruby

Bringing Objects To Views

View Comments

Ruby on Rails is a fine framework. It uses Ruby which is beautiful programming language. Everything is an object in Ruby, and the block structure allows you to do marvelous stuff with it. The Rails team is well aware of this and uses it, making Rails a great partner in crime. I still remember the first time I viewed the migration for creating a new database table:

create_table "users" do |t|
  t.column :name, :string, :limit => 40
  t.column :email, :string
  # etc
end

I almost didn’t recognize it at first. I didn’t know Ruby back then, I just did what was necessary to make it work without looking at what it does. But take a good look at what it really does. It creates a table and gives you an object for you to play with. Within the block you can edit the properties of the thing you’re creating in small readable lines. Ruby itself is full of these functions. Iterators are probably the best examples. Read the rest of this entry »

Written by Iain Hecker

April 26th, 2008 at 12:50 pm

Posted in Uncategorized

Surrounding something with a div, conditionally.

View Comments

A problem I keep running in to, especially with Haml, is how to render Ajax requests. Say you have a partial on your page which is something dynamic, like a feedback form. Here you might want to replace this partial with an updated version of that same partial. When making an ajax request, you specify the id of the element you wish to update. But when the element is created inside the partial, it gets rendered double. Read the rest of this entry »

Written by Iain Hecker

March 20th, 2008 at 10:27 pm

Posted in Uncategorized

Leef je doel live!

View Comments

This is my first Dutch post on my blog. It is about the release of one of my biggest projects ever to go online. It’s a Dutch website, therefore this post is also in Dutch. If you can’t read it, try google translate or keep on reading my other posts.

Alhoewel het project nog niet helemaal af is, staat het project wel al online. Ik heb het over LeefJeDoel.nl, de site waar je de doelen die je nog wilt bereiken in je leven kan inventariseren, geïnspireerd kan raken door de doelen van anderen en met anderen met dezelfde doelen in contact kan komen.

Leef Je Doel (logo)

Read the rest of this entry »

Written by Iain Hecker

March 10th, 2008 at 9:52 pm

Posted in Uncategorized

Second Haml evaluation

View Comments

After using Haml for over a month now, I can now really evaluate how Haml is to work with from day to day basis.

Haml actually is a blessing. Doing minor adjustments is very easy, your code remains looking nice, the output keeps looking nice. Just be sure to know how to shift blocks of code to the left or right in your favorite editor. Read the rest of this entry »

Written by Iain Hecker

March 10th, 2008 at 9:20 pm

Posted in Uncategorized

First Haml evaluation

View Comments

As I promised, here is the evaluation of redoing a site from ERB to Haml. To immediately cut to the chase: Haml IS worth it!

  1. It’s so definitely faster and easier to write than ERB.
  2. Your HTML output is nicer.
  3. Partials rendering with the right indentation automatically.
  4. It forces you to take a good look of what you’re actually making.
  5. Because it’s so strict on it’s syntax, you will be using more helpers and custom model methods, which is a good thing.
  6. No more forgetting to close a div and spending hours to find out which one.
  7. Faster refactoring because of less code and easier to read.

There are some downsides however. I’d rather not talk about the hours I tried to fix some idiot problem with partials and the locals option. Just use locals as less as possible, preferably not at all. Read the rest of this entry »

Written by Iain Hecker

February 15th, 2008 at 1:59 pm

Posted in Uncategorized