Shopify/batman — Issue #345: Model.find
Author: meskyanichi
Created: 2012-02-29 01:02:10+00:00
State: open

Hi,

I'm new to Batman and am using Mongoid, Rails 3.2.1 and Batman-Rails. I'm trying to figure out how to do something pretty basic but I simply cannot figure out what's going wrong here.

```coffeescript
class MyApp.AppController extends Batman.Controller
index: ->
MyApp.User.find "4f4c29ec8aa92ae613000001", (err, user) =>
@set "user", user

class MyApp.User extends Batman.Model
@primaryKey: "_id"
@persist Batman.RailsStorage

@encode "_id", "email"
@encode "created_at", "updated_at", Batman.Encoders.railsDate

window.MyApp = class MyApp extends Batman.App
@root "app#index"
```

The error I am receiving: `Uncaught TypeError: Cannot read property 'user' of null`

Any idea what I'm doing wrong?

Thanks

Notes:

* Yes, I am explicitly passing in a static string to the `find` method just to clarify that it has nothing to do with parseInt() or w/e other utility breaking the `_id`.
* Using latest versions of Rails, Mongoid and Batman (assuming the latest version of Batman ships with Batman-Rails)