Daily photograph for 2008-05-11 - "bus stop"

Today's photograph on my photoblog, "Photo-Persistence"

Archive for

Ruby On Rails Active Record gotcha

Thursday, May 11th, 2006

I’ve been trying to do some Ruby On Rails development in my spare time for a personal fun project. I’ve been through almost every RoR tutorial, I’ve got the Agile Web Development with Rails book and read the majority of it, and written a very popular Ruby On Rails Cheatsheet. But every time I try to display relationship details between tables, I always got errors “undefined method“. I couldn’t see why this would work in my tutorials, but never in my own personal work. It all came down to a single letter - ’s’.

For example, if I had 2 tables; Notes and Comments with a One To Many relationship. Tables are as follows:

create table notes (
id int not null auto_increment,
body varchar(60) not null,
primary key (id)
);

create table comments (
id int not null auto_increment,
details varchar(40) not null,
note_id int not null,
primary key (id)
);

It wasn’t until I referred back to Amy Hoy’s ActiveRecord cheatsheet (Thanks Amy) that I finally found my problem. This is the one time where (my assumed) convention bit me in the ass instead of working for me. Looking back and “reading code as english” as you can commonly do with Ruby code, it makes sense.

class Note < ActiveRecord::Base
has_many :comments #note the pluralization
end


class Comment < ActiveRecord::Base
belongs_to :note #note the singular reference
end

I had previously thought the convention was that both has_many and belongs_to refered to a singular reference (comment & note). Not so. If you read the code “Comment belongs_to :note” and “Note has_many :comments” it makes perfect sense.

So in my view, I would try to reference fields like note.comment.details and get the error undefined method as the code was looking for the method note.comment instead of a related object. As soon as I fixed my model by adding the ’s’ to has_many, everything worked right away.

Newbie mistake I guess. I’m sure it won’t be the last.

Technorati Tags: ,

is ajax the new blink tag?

Thursday, May 11th, 2006


I was listening to a SXSW podcast this morning on the way into work about “Ajax — What Do I Need to Know” and Jesse James Garrett said the following about Ajax.

People tend to think of Ajax as a magic bullet … but it’s a bullet it’s really easy to shoot yourself in the foot with.

That got me thinking. Now that it’s so easy to add rich UI content, I predict we’ll see the same thing as when HTML and Javascript initially became popular - when people used the <blink/> tag on websites just because they could. And everyone knew how to copy and paste javascript to add statusbar tickers and marquees to their pages just to show everyone how cool their pages were. More javascript means cooler design, right?

Counters and clocks, animated gifs of everything, javascript rollovers were all the “it” thing to do. I think we’ll see the start of same thing with AJAX for the first while as it becomes popular and everyone wants to put Google Maps on their site and become a part of Web 2.0. 2 years from now, it’ll remain useful for creating real content and it’s won’t be so much hype anymore. By that point, people will have moved on to the next hot thing - embedding video feeds everywhere in their pages.

Technorati Tags: , ,

Photo Workflow

Monday, May 8th, 2006

Here’s my latest digital photography workflow. Previously, I didn’t have anything formal. I would dump out some photos, edit them and I’d have them scattered among several different directories, not backed up, different sizes, couldn’t find the originals to go with the edited versions. I’m paying for it now as I’m trying to resort all my old photos. Hopefully this will keep me on track.

How does your workflow go?

Technorati Tags: , ,

2 years and counting

Monday, May 8th, 2006

ostrich

Today is J and my 2nd year wedding anniversary. Time has flown by. It’s been an amazing time with her and I look forward to a lot more years laughing together. Since today is a weekday, we had our celebration on Saturday. It was J’s turn to plan the secret fun, I did it last year. And she didn’t disappoint. We were up early on Saturday, we got in the car and she made me keep my eyes closed the entire drive - the whole day was a secret. 45 minutes later, the car stopped and I could finally open my eyes. Toronto Zoo! I’d never been to a zoo before and I’d always told J I wanted to go. And the other great thing was that she made sure I had fully charged batteries and a fresh memory card for my camera, ready to go. The day was full of photo opportunities. I shot 300 photos and a great deal of them are keepers. I’ll be posting them soon. The weather was a bit chilly in the morning but warmed throughout the day. 6 hours of walking around the zoo exhausted us. Then we went out for a great dinner (mmm….steak) to finish the day.

J, happy anniversary to us!

Check out photos from the Zoo.

Technorati Tags: ,