Bringing Objects To Views
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 »
Surrounding something with a div, conditionally.
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 »
Leef je doel live!
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.
Second Haml evaluation
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 »
First Haml evaluation
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!
- It’s so definitely faster and easier to write than ERB.
- Your HTML output is nicer.
- Partials rendering with the right indentation automatically.
- It forces you to take a good look of what you’re actually making.
- Because it’s so strict on it’s syntax, you will be using more helpers and custom model methods, which is a good thing.
- No more forgetting to close a div and spending hours to find out which one.
- 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 »
