I ran in to this error:
Uncaught TypeError: Cannot call method ‘dispatch’ of undefined
The first thing to check is that your route exists. I created a utility located here: https://github.com/RyanonRails/batman.utilitybelt that can list out your current routes.
If the route exists, you need to make sure that your controller names are named correctly as such:
1
2
3
4
5
@resources 'sections', 'sectionrows'
-------------This would looks for these 2 controllers------------
class EST.SectionsController extends Batman.Controller
class EST.SectionrowsController extends Batman.Controller
I ran into this because of the above 2 word model. For future reference here’s the layout I used:
Driver (/est.coffee):
1
2
3
4
5
6
window.EST = class EST extends Batman.App
  Batman.ViewStore.prefix = 'app/views'
  @controller 'sectionrows'
  @model 'sectionrow'
  @resources 'sectionrows'
Controller (/controllers/sectionrows_controller.coffee):
1
2
3
4
5
6
class EST.SectionrowsController extends Batman.Controller
  routingKey: 'sectionrows'
  index: ->
    EST.SectionRow.load (err,results) =>
      @set 'sectionrows', results
Model (/models/sectionrow.coffee):
1
2
3
4
5
6
7
class EST.SectionRow extends Batman.Model
  @resourceName: 'sectionrow'
  @url = "/api/sectionrows"
  @set 'primaryKey', 'SectionRowId'
  @persist Batman.RestStorage
  @encode 'SectionRowId', 'WorkType'
View (/views/sectionrows/index.html):
1
2
3
4
5
6
7
8
9
<h2>All Section rows</h2>
 
  <div data-foreach-section="sectionrows" data-mixin="animation">
    <a data-bind="sectionrow.SectionRowId" ></a>
    <p data-bind="sectionrow.WorkType"></p>
  </div>
 
Total # of sections: <span data-bind="sectionrows.length"></span>
Batman 0.9
