Category Archives: Tutorials

Objective Resource for Faster iPhone Development

I recently came across Objective Resource for developing iPhone applications that talk with a Rails backed website. According to the site,

ObjectiveResource is an Objective-C port of Ruby on Rails’ ActiveResource. It provides a way to serialize objects to and from Rails’ standard RESTful web-services (via XML or JSON) and handles much of the complexity involved with invoking web-services of any language from the iPhone.

I’ve had a chance to play with it this weekend and have found it to be pretty easy to work with. The developers of Objective Resource have created a pretty good Getting Started Guide you can follow, or you can watch a screencast of it as well. They even offer an example project for you to work with that gives you both the iPhone app (via Xcode) and the Rails app so you can see how everything works together.

One thing the example project does not include is accessing a Rails app that has authentication. Of course I was thinking I was all setup for this, but soon realized that I did not add my Active Resource functions in so that my app would work with XML/JSON requests. Luckily, while I was out in Denver, CO for iPhone Development Training (by Pragmatic Studio) I was able to get my hands on a copy of Advanced Rails Recipes by Mike Clark. I was extremely pleased that Mike graciously gave me the copy he had laying there for free. The particular recipe in the book that helped me was the Authenticate REST Clients. After I rewrote my authentication piece of my Rails app, I was getting data back and into my iPhone app. It was a very good feeling!

I thought I would include the screencast that the Objective Resource developers created. It runs about 6 minutes and is definitely worth a watch if you are looking at using Objective Resource for your next iPhone app backed by a Rails app.


Getting Started with Objective Resource from Josh Vickery on Vimeo.

Todo list application with Rails 2.0!

I’ve recently taken a new position doing Rails applications full time (which I’m definitely excited about) however, between myself and the other developer, we’ve decided to go right up to Rails 2.0.2. This of course did not fit with me very well because I haven’t done rails development full time yet, and what rails apps I have done were in 1.2.6 and lower. I haven’t been a good developer because I wasn’t paying attention to all the new features and how they work. Of course I posted awhile back about some of the new updates here, but that’s about all I’ve done with Rails 2.0 until last week when I started my new job.

This is tutorial 1 of a new series I’m creating for making a simple CRM application that you can use for some of your daily tasks. Today we are going to create a simple todo list without writing any code (well to start off with). First create lets create a new app by typing,

rails -d mysql todo (I’m adding -d mysql, because sqlite3 is the default database and I’m using mysql)
cd rails

Next, we need to create our databases so we can type the following with rails 2.0.

rake db:create:all

Now that we’ve created our databases, it’s time to make our controller and model. For this, so that we don’t have to write any code, we’ll go ahead and scaffold this. We’ll type the following.

script/generate scaffold Todo title:string body:text done:boolean due:datetime

We can now migrate our database so we’ll type this.

rake db:migrate

Finally, all we have to do is start our server.

script/server

Then we can go to http://localhost:3000/todos and we’ll see our index page. You know have a working todo list, not very design oriented of course, but you are well on your way to making it yours. I’ve put up the application the way it should look here.

If you are looking for a version of this with pre-2.0 of Rails, you won’t be able to use the “rake db:create:all” command, so you’ll have to make your database another way. In the next tutorial we’ll add a customer database with a custom search so that we can search all your customers. Until next time folks!