Archive for the 'Ruby on Rails' category

resource_hacks: A Restful Plugin You’re Likely To Need

The new app I’m working on is using EdgeRails, SimplyRestful and all the rest, so I’ve been learning a lot and bumping into situations I don’t immediately know how to handle. One of those is how to access resources using arbitrary keys in the URL.

For example, let’s say you want to show all the items in your application that have been tagged with the word ‘rails’. In the purely Restful world, your URL for that would be mapped like this:

map.resource :tags

which would give a URL like this /tags/:id where :id represents the unique id of the ‘rails’ tag in the database. While that may be correct, it’s not pretty, and it’s not intuitive for users.

You could hack something together so the system still used a numeric id but appended some textual “meta-data”, as John Susser has discussed. But in my opinion, for this example even that is inadequate. What if the user decides to switch the tag in the URL from ‘rails’ to ‘ruby’? They’d also need to swith the unique id in order for things to work.

Fortunately, Jeremy Voorhis has a fix; it’s a plugin called resource_hacks, and it allows us to use any kind of key we want in the route. So now our mapping becomes:

map.resource :tags, :member_path => ‘/tags/:tag_name’

Which would give us the nice /tags/rails URL we wanted.

There’s some debate on Jeremy’s blog about whether this should get into trunk, and it looks like for now it will stay out due to a difference of opinion about whether it’s right. But it’s clearly called for in my case, so I’m going to go ahead with it.

Can anybody think of a better way of solving this problem, perhaps one that would allow both numeric and non-numeric keys in the URL?

YFly opens up to all users, adds video uploading

YFly.com, the Ruby on Rails social networking site I helped build over the past four months, released a new version today. Now anybody can sign up, and anybody can add video, HTML and images to their profile page. Check out my profile!

yfly_profile.jpg

I had a great time working on this project. I learned a ton and worked with some great people at Space150; it was a great opportunity and I’m proud of what we accomplished.

MissingMethod plugins available via SVN

I’ll be making some of the Ruby on Rails plugins I’ve written available for checkout via SVN. I took some time today to set up the repository and add the first plugin, DecimalMigrations.

DecimalMigrations allows you to use decimal numbers when naming your Rails migrations, which comes in handy when you have to go back and change an old migration or insert something new. This obviously goes against some of the logic of migrations in Rails, and it’s basically an ugly hack, so please use it carefully and sparingly.

To install:

ruby script/plugin install http://missingmethod-projects.googlecode.com/svn/trunk/plugins/decimal_migrations/

Or just check out the source from Subversion:

svn checkout http://missingmethod-projects.googlecode.com/svn/trunk/

Sneakology gets a companion

Sneakerplay is a “sneaker-based social network which has been in private beta for the past few months” and just opened up. According to Mashable.com it’s “an incredibly simple network that lets you create a profile, add pictures of sneakers and put two pics head to head using the “battle” feature.” Better still, they managed to get a promotional deal with Nike Air.

Things that are funny about this to me:

  1. We built practically the same thing with Sneakology.
  2. We built it in 24 hours, as part of the RailsDay2006 competition (which, by the way, still hasn’t announced winners).
  3. We didn’t get a deal with Nike.

Anyway, props to Robleh, Mohamed and Rob (the developers) for executing on a nice idea and getting the promotional buy in from a major player.  When we developed Sneakology, it was  mostly for fun, and  we didn’t imagine it had much business potential. I’m glad to see we may have been mistaken.

So You Really Want to be a Rails Hacker

I stumbled on this article describing the steps to becoming a Rails hacker, and I have to say I disagree with most of it. Read the whole article and see what you think. Here are some excerpts, and my responses.

Before you start, well, you have to go into some sort of Zen retreat. You have to rid yourself of all legacy notions you might have about writing software. Leave your best practices behind you.

I don’t know if this is tongue-in-cheek or not, but it’s wrong. Unless you’re terribly closed-minded about web development already, there’s nothing special you need to do to prepare for working in Rails. Most people I know actually find the opposite; it’s easy and intuitive, and things just make sense.

Next pick up the Pickaxe or Ruby for Rails, preferably both.

OK, I’ll admit I like programming books less than the average developer, but come on… do you really need to go out and spend money on a book to learn build an application in Ruby on Rails? There are tons of completely free references online, including Why’s Poignant Guide, Snippets, the Ruby On Rails Wiki, Try Ruby, PeepCode, the Ruby Quiz, and countless others I can’t even begin to name (feel free to leave them in the comments). If you’re into holding a stack of paper while you code, that’s fine, but it’s definitely not a precursor to ACTUALLY CODING SOMETHING.

Now what, ah, yes, get a mac. Not because they look cool or anything but get it because you can use the text editor TextMate. TextMate is a Rails’ progger main tool, it’s text editing on steroids and again you will love it.

I agree: TextMate rocks. Hard. But you don’t need to buy a Mac to get started with Rails. Rails is open source and platform independent. MySQL too. RadRails is an Eclipse-based IDE that works on Mac, Windows and Linux, and you could do a lot worse than my favorite Windows IDE, NotePad2.

Bottom line: the best thing you can do to become a sucessfull Rails hacker is … START HACKING. Build something. Release it to the public. Even it’s crappy and buggy, you’ll learn a lot and you’ll have SomethingRealThatYouBuilt to point to when trying to convince someone to hire you. That’s more than most hackers have.

Sneakology Updates

header_logo.jpgJust wanted to point out that I’ve made a few updates to Sneakology.com, the sneaker-afficionado social-networking site I helped build for RailsDay. I tweaked some of the copy and added a tips section that appears when you log in, all in hopes of lowering the initial barrier to entry and making the site a little more intuitive. Check it out and let me know what you think!

Prototype.prototype = {updated: true}

Justin Palmer has the rundown on the latest in a series of pretty significant updates to everyone’s favorite Javascript library. As usual, he’s got an in-depth breakdown of what’s new. I encourage you to read it if you do any Javascript programming at all, as it shows the direction the library is going in.

Among the coolest new features is traversing the DOM with simple Element methods:

$(‘element‘).up();
$(‘element‘).down();
$(element‘).next();
$(element‘).previous();


Browse Images in TextMate

Looks like TextMate has a pretty sweet built-in interface for browsing through images; all you need to do is install the ImageBrowser bundle (download and run this script to install it), and then hit control-shift-i to see something like  this:

img_browser.png
It makes finding and inserting images into your code a breeze.

via iamrice 

MinneDemo WrapUp

Last night’s first-ever was a great opportunity for business-owners, entrepreneurs, and developers to get together and share ideas. Organized by Dan Grigsby, and Luke Francl, the event drew attracted a diverse group of about 90 people who came to watch the six demos. A big thanks goes out to sponsors New Counsel, Ventera, and Slantwise Design for making the even possible.

The presenters were:

  • Robert Metcalf of FlySpy.com, who showed us how visualizing the airfare marketplace can help people make better decisions about where and when to travel (I plan on using it to find a better airfare for my trip to RubyConf).
  • JRuby’s Charlie Nutter, who (as always) wowed everyone with his guru-like understanding of how Ruby works.
  • Jon Dahl, who talked about SaySwap, a video-game sharing site built in Ruby on Rails built by his company, Slantwise Design.
  • Aaron Fulkerson of MindTouch talked about DekiWiki and Dream (sorry, I missed most of this one, anyone want to fill me in?).
  • Garrick Van Buren showed off Feedseeder, a sweet-looking blog aggregator that tries to fix what a lot of other readers have gotten wrong. Best of all, Garrick told me he was able to learn a few things from looking at the Feedmarker source code! Go open source!
  • Brian Huff demoed Bookmarkit.org, a free service that allows you to submit a bookmark to multiple social bookmarking sites with the greatest of ease.

I had the good-fortune of being asked to greet people at the door, so I got to meet more interesting peoplel than I’m capable of remembering (sadly). But it was definitely encouraging to see so many other entrepreneurial people gathered in one place; makes you want to get out there and do something!

RailsDay Judging Delayed Again

Too bad nobody built an app to help judge RailsDay applications. That would have been 24 hours well-spent, because the RailsDay judging has again been delayed. RailsDay was June 17th, it’s now August 13th, coming up on two months. I can understand how much work it must be to judge all those entries, and I definitely sympathize with the judges, who must have about a billion other things to worry about.

railsday.jpg

Still, it’s a shame the process couldn’t have gone more smoothly, and I hope it does next year. I say this not so much because I’m impatient and want to find out who won, but because the RailsDay competition was a great way of building momentum for Rails and the Rails community. It would have been great to build off the buzz of RailsDay to show how much quicker development with Rails is, and how agile and alert the community is. Unfortunately, because of the delays, we’ve lost a lot of that initial momentum.

In any case, I hope the new judges are able to get the results out quickly, and I’m still grateful to all the organizers and volunteers who made RailsDay possible. Regardless of the results, it was a great experience.