Wednesday, July 2, 2008

Contributing to Rails is easier than you think

Rails_2At OtherInbox we love open source and are looking for ways to share some of our labors with the community. Today I came across a great opportunity to contribute something to Ruby-on-Rails core development. I'm posting it here so everyone can see how easy it is to contribute.

I was building a JSON API to enable some new awesome features we're working on. Following the JSON request specification, I had the client setting its MIME type to "application/jsonrequest". But this was not causing Rails to recognize the request as JSON and thus the request body was not properly parsed. After doing some digging, I realized that Rails only looks for MIME type "application/json".

Fortunately, MIME type processing is implemented really humanely in Rails, so I whipped up a little patch that adds "application/jsonrequest" as a synonym for the JSON MIME type. First I wrote a test to prove that this was a problem. Once I had a failing test, I added the MIME type, and got my test passing. I followed the git patch instructions on lighthouse, then jumped into IRC #rails-contrib to garner support for it.

I happened to see that Rick Olson, the author of the existing JSON parsing code, was in the chat, so I pinged him with the lighthouse ticket. He tested it and applied it, and now our one line of code is a part of Rails!

Hopefully this will save some future JSON implementer a bit of pain.

Cross-posted from the OtherInbox blog


John Trupiano said...

Congrats Mike! btw, I started down this same path (writing up a blog post about contributing to rails), but ended up finding that my problem had already been fixed in edge. Check out the post about rails 2.1 breaking foreign keys in the test environment.

Anyways, just wanted to say congrats to a fellow Baltimore rails dev. We'll have to catch up soon.

Mike Subelsky said...

Hey John, Thanks! I've been bit by the schema dumper before as well. Have you tried switching to SQL dump instead? Haven't really messed with that, wonder what the tradeoffs are.

Anonymous said...

MBT Sport
MBT Tupu
MBT Wingu
MBT shoes