At
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.