Insights on Ruby, Git, jQuery, Cappuccino, WordPress, Debian and OS X. Please subscribe if you find something useful!

Cappuccino On Rails

Posted: January 12th, 2010 | Author: Jerod | Filed under: Cappuccino, Projects | Tags: | Comments

I’m happy to announce the release of CappuccinoResource (CR), a library dedicated to interfacing between a Cappuccino front-end and a Rails back-end.

CR should feel very familiar to Rails developers. Its interface is akin to ActiveResource and it borrows heavily from the (very good) ObjectiveResource library for the iPhone.

All basic CRUD operations are supported, and you can perform advanced finds with arbitrary parameters. A brief example of fetching a record, modifying it, and saving it:

var post = [Post find:@"42"];
[post setTitle:@"Why X is Better than Y"];
[post save];

Check out the README on the project’s page on GitHub for more details and usage examples.

Live Demo

I also created a demo application which is a simplified clone of OS X’s Address Book. The demo is live on Heroku. Check it out. The source for the demo is also on GitHub.

If you’re a Rails developer waiting for a good opportunity to try out Cappuccino, there’s no better time than now.

If you’re a Cappuccino developer looking for an easy-to-use, powerful back-end for your applications, Rails might be the answer for you.

CR is a young project, but it drives one of my client applications that is production-ready (albeit not deployed), so I believe it is ready for prime time. Please try it and let me know how it goes.

Fork, report issues, et cetera.


  • That looks nice. I developed something similar for myself. It's great to see people around working on this. I'll check it out to inspire me :)
  • Jerod, I've been working with Cappuccino, but my background is Cocoa, so this does some "heavy lifting" for me. Thank you!
  • Very cool, happy to help out. Please let me know if you release anything that uses my library!
  • aaronbrethorst
    woohoo! this looks awesome, thanks!
  • Edward Ocampo-Gooding
    This looks pretty similar to Nick Small's CPActiveRecord: http://github.com/nciagra/Cappuccino-Extensions......

    Was there any code borrowed?
  • Actually, I was using CPActiveRecord for some time on my application before writing CR (I even contributed a couple of small things to his library). However, my application's needs outgrew that library and as I spoke with Nick he stated that it might take a rewrite on his part to facilitate them. That is when I decided to write a separate library.

    There may be one or two lines of code borrowed, but more importantly I borrowed a lot of the good ideas Nick included (specifically, the notification system). I also borrowed ideas from ObjectiveResource as that project has a very similar goal.
  • Ted
    Nice work. This looks like a really good library.

    I've been curious about Objective-J.. how much modification was necessary to go from ActiveResource to CR? I guess you can do away with all the parsing code, for the most part, and just use JSON, but what about the reset of it?
  • Hi Ted-

    I only mimicked ActiveResource's interface, not how it works (I've never read AR's codebase). You are right though, handling JSON responses are very easy. All I had to do in CR is determine what kind of response it was (string, date, number, etc) before setting the matching ivar because Cappuccino doesn't store ivar types for later retrieval (yet).

    Overall working with Objective-J is great. The syntax was strange to me at first, but once you get used to it it feels very flexible. If you are familiar with Objective-C you'll pick it up in no time. Plus, since its a strict superset of JavaScript you can use everything JavaScript has to offer without any problems.

    For one project I even mixed in Underscore.js and was using _.each, _.include, and all the other goodies that library provides right in with my Objective-J code. Very cool.
  • Jerod, this looks fantastic! I haven't taken the time to even play with Cappuccino yet, so I maybe this is my chance!
  • Thanks Doug!

    Cappuccino is very cool when building rich web applications. I spent the last couple of months working on a client project that has turned out very well. Its amazing how much you can do without writing a single line of HTML or CSS.

    Do give it a try if you get a chance.
  • SIngAlong
    Now it would be nice to have a HowTo for those amateurs like me and Douglas to start using CR with capp and Rails instead of going thru a full circle learning Capp and then figuring out how to connect it to a rails backend. I understand learning capp is essential to use CR but still a lot of people would be comfortable with a howto that introduces them to capp and then to CR, therefore allowing them to start off with rails backends with capp
  • I think that is a good idea. There is a lot to learn with Capp (since you're picking up a language and a framework at the same time). The demo application I wrote was intended to help people see how the two work together. Perhaps I should write a blog post (or screencast, if it isnt too long) walking through how I created the demo app.

    If you want a good resource list on learning Objective-J and Cappuccino, check out a blog post I created sometime last year:

    http://blog.jerodsanto.net/2009/11/learning-cap...
blog comments powered by Disqus