If a user has bookmarked, or shared the following URL, how should my one page backbone.js application (uses Backbone.Router) go about retrieving the required data in order to render the complete view?
http://mydomain.example.com/menus#/menus/99/items/33/ingredients
If the user bookmarked http://mydomain.example.com/menus I can easily bootstrap the first page of menus.
# Inline before </body>, in a <script> block
Menus.reset(<%= @menus.to_json %>);
But in the case I mention above, there's 3 layers of bootstrapping required, yet since this is #hashtag navigation, the server does not know to bootstrap Menus, Menu of :menu_id, Items, Item of :item_id and the first page of ingredients.
# It would look like the following on a real page
# http://mydomain.example.com/menus/99/items/33/ingredients
# please see past the invalid syntax
Menus.reset(<%= @menus.to_json %>);
var menu = Menus.get(99);
menu.items.reset(<%= @menus.find(99).items.find(:all).to_json %>);
var item = Menus.items.get(33);
item.ingredients.reset(<%= @menus.find(99).items.find(33).ingredients.find(:all).to_json %>);
Is there a pattern that others use to accomplish this? Does this make sense to you?
I have a strong urge to create a bootstrap controller with the sole purpose of fetching all the models and collections required to draw any page. /bootstrap?path=/menus/99/items/33/ingredients and then have that return some jsonp to the caller page http://mydomain.example.com/menus#/menus/99/items/33/ingredients.
Thanks in advance.