Archive for August, 2005

Posted on August 18, 2005 at 5:48 pm

Back from vacation in New York. We had a great time and did a lot of cool stuff. Walked our asses off too. New York is a great city, with a lot energy and good things going on, but it’s nice to be back in Portland where things are a bit less frenetic.

Posted on August 14, 2005 at 9:54 pm

We’re having a blast here in New York. What a great city, with so much energy! I love it. Today as we were leaving The Producers, we happened to catch Yoko Ono coming out of the new Lennon musical with all of her body guards. I just managed to snap a photo with my cell phone. My cell phone takes shitty pics, so sorry about the quality. This photo was taken from about 4-5 feet away.

Yoko2

A couple of minutes later we were cutting through an ally and we spotted Jeff Goldblum signing autographs. Here’s another really crappy quality picture.

Jeff2
Since we were just coming from a show, this was the only time during the whole trip that I wasn’t carrying my camera!!

Posted on August 10, 2005 at 4:11 pm

I attended Jim Weirich’s Dependency Injection session at OSCON 2005 last week and over the weekend I started thinking about how I could create dynamic controller action names in Ruby on Rails using the method_missing technique he discussed.

I’m working on a new application in Rails, and if a user forgets their password I would like them to just click a single link to get their password emailed to them. Having them fill out yet another form is just uncalled for and passing the username as a get variable is just plain ugly.

What I want is a dynamic method name, so that instead of the link going to a generic action name like:
http://www.infused.org/account/send_password

It would go to an action name specific to the user:
http://www/infused.org/account/send_password_to_bob

To accomplish this, I override the default method_missing method in the account controller:

def method_missing(m)
  send_passwd($1) if m.id2name =~ /^send_password_to_(.+)$/
  redirect_to :action => 'login'
end

def send_passwd(login)
  # send the password here
  flash['notice'] = “Your password has been emailed to you.�
end

The method_missing method will catch any action names that don’t exist, so it first checks to see if the method name matches the regular expression /^send_password_to_(.+)$/ and if so, passes the matched username to the send_password method.

The final redirect to the login action will get called whether or not send_password was called. Otherwise, a missing template error would be displayed for anything not matching the send_password regular expression. I would rather raise the standard ActionController::UnknownAction error if the method name doesn’t match the send_password criteria, but there appears to be a bug in Rails 0.13.1 that prevents it from working. The ticket shows that this should be fixed by 1.0, which is right around the corner.

I think this is an elegant way to handle the problem without passing an ugly get parameter (or worse). Doesn’t it make more sense to say send_password_to_bob than it does to say send_password?to=bob?

Does anyone know of any problems I’m creating for myself by using this approach?

Posted on August 8, 2005 at 10:09 pm

Due to the seemingly never ending saga of our bathroom remodel there are 28 pending comments in the genealogy section of the site. Some of you have been waiting as long as two weeks for a reply, so I apologize. I’ll try to clear the backlog over the next day or two.

Posted on August 5, 2005 at 11:41 am

A few more happy shiny links from OSCON 2005: