My app allows users to design crepes, and so far it has two models, Crepes and Ingredients:
toString on both of the models because when a JS object instance is rendered as text,
toString is called automatically.
My app defines
/ingredients, and I want each of those pages to show a side-bar nav that lists all items and provides a link to create a new item. So, I added a
nav to my Rails layout where I will render my
Creperie.ContextNavView. I attach the
Batman.View with the
data-view view binding:
/ here is my context view: nav data-view='ContextNavView' section#main data-yield='main'
This is made possible because Batman (v 0.15.0) keeps track of the current route at
MyApp.currentRoute (which you can access in your code or in the console as
MyApp.get('currentRoute')). Since my controllers are all defined with Rails-style names, I can count on the controller names matching the model that I want to display.
Last, I defined the template which
ContextNavView uses as its source:
a.edit data-route='routes[itemRoute][item].edit' edit
The big win here was sending strings to
 in the keypath. That way, I could meta-program my routes – I didn’t have to make them explicit.
MyApp.currentRouteto get information about the current page.
Batman.Viewto provide site-wide navs (or other views).
- Meta-program your routes (or other parts of the nav) by using
in your keypaths.