Ryan Bigg

⟵ Posts

This is genius!

24 Oct 2008

I read Mike Gunderloy’s blog post today and afterwards thought he was crazy! I thought you couldn’t do Blog.find(“1-title”).

But you can.

If you pass in 1-title as params[:id] for any action and then pass it to find, find will do its “thing” and just execute find(1), giving you pretty URLs AND pretty code.

I later found out this was because find just calls to_i when it gets given strings, and calling it on “1-title” will give you “1”.