LocationBot
Suneth and I decided to take a quick stab at solving iOS6 Map’s annoying lack of business listings (by that I mean Suneth pretty much writing the whole thing!). We are pretty much done with a fully functioning app that helps you search either Google Places API / FourSquare Venues API and get a set of results. When you find what you’re looking for, you can quickly use the app to flip over to iOS6 Maps for navigation with just one click!
More about it later…
But here’s my awesome icon (LocationBot). Not too bad for an hour’s worth of work… right? Attempt #2.
And just for reference, here’s the failed attempt #1:

Rails Validating Field vs Association
One really interesting thing I came across recently is validating a field vs association. I’ve always written something like this (assume this is a… Company model with a attribute called owner_id and a belongs_to association called owner):
validates_presence_of :owner_id
What’s better to write is:
validates_presence_of :owner
This actually makes sure that your :owner_id actually maps to a real object in the database. So you can’t just set a random integer as owner_id and get away with it!
Sadly this has made testing a little bit harder. Tearing through FactoryGirl documentation again now!
Talking to a cross-domain API (CORS) with Backbone JS and Ruby on Rails
After doing a whole load of reading, the solution is absolutely simple. Here’s what to do. On your backbone (or any other client side JS) side, we add some jQuery goodness with the following method:
$.ajaxPrefilter( function( options, originalOptions, jqXHR ) {
options.url = ‘http://yourdomain.com’ + options.url;
});
This prefilter allowed all my BackboneJS calls to be hitting the remote API correctly. I’ve put this on my main.js before the router is initialised just to be sure.
The difficult bit was the server support for CORS (cross-origin resource sharing). Browsers don’t like to let webapps just talk to other domains by default and require the server to specifically support this.
With CORS, there’s generally 2 calls made. The first call is a test from the browser with the HTTP header OPTIONS. Browser asks for what HTTP headers, requests and origins are allowed by the server. Your server has to respond accordingly or none of this will work. The next call is the actual backbone fetch() call.
After all that reading… yes, someone made a fantastic gem for this purpose!! Rack-Cors (https://github.com/cyu/rack-cors) is a rack-middleware addon. The setup instructions are there, it works with rails 3. Quick sample below from application.rb. And that’s it!!
config.middleware.use Rack::Cors do
allow do
origins 'https://yourdomain', 'localhost:3000'
resource '*', :headers => :any, :methods => [:get, :post, :options]
end
end
ActiveAndroid
Good shot at bringing #Rails’ ActiveRecord functionality to Android apps. Keep an eye on it!
An MVP is the smallest solution that delivers customer value.
Behavior Driven Development
Great introduction
CanTango gem - User roles & permissions management on rails

This is really the ultimate user role management gem! It is derived from another popular gem called CanCan, written by the great Ryan Bates himself (guy who does railscasts). This gem really builds on the humble beginnings of CanCan. Some of its core features:
- Managing user roles
- Permissions per user, account type, roles and roles groups
- Lots of features like caching engine to autoload permissions etc.
- Categories, licenses etc etc etc!!
Endless ways to extend the functionality, check it out!
Selectively merging branches with git
git-checkout is the key here. Here are the quick steps:
- Checkout the branch you want to merge into: git checkout production
- git checkout feature_branch_name <list of files> to merge just the changes from specific files: git checkout push-notif-branch app/controllers/controller.rb config/certificates/* …
- Git automatically does a git add into your initial branch with the files you specified. Just follow up with a git commit -m “message” and you’re done!
Ruby on Rails: Deleting data models without deleting from database
Act as paranoid is a great little gem if you want to keep your models to hang around for audit purposes till some later process clears it out. Calling ActiveRecord.destroy first time removes it from all queries and the next destroy removes it from the database entirely. Fantastic. Rails 3.2 compatible.
This is how you present a compelling argument #iOS6
