0

I have read several tutorials about using backbone on rails but I still have no clue on how to intregrate backbone with the app that I'm developing in rails.

The thing is that I have an events page (event is a rails model and an associated controller) which has a tabbar with one tab for each one of its categories (the event has nested categories). I want to use backbone in this particular page of my app because inside of each tab I will have many javascript code. Each tab would represent a category of the event.

Any idea of how I can use backbone for this?

I also want to user twitter bootstrap for my views, is this also possible to do if I use backbone?

Hope I made myself clear. Thanks,

Martin

1 Answers1

1

Twitter bootstrap is compatible with Backbone

http://coenraets.org/blog/2012/02/sample-app-with-backbone-js-and-twitter-bootstrap/

If he is doing it its not a bad idea

The standard idea with a backbone page is that the rails will serve up json for the objects (either inline for single request or as an api style second request).
the key to fetching a collection (many models) is the fetch command http://backbonejs.org/#Collection-fetch So the tabs would be a collection to start

Does that point you in the right direction?

MarkKGreenway
  • 8,494
  • 5
  • 34
  • 53
  • Great thanks! That's a good start point! And the initialization code for backbone must be in the event's view or in the applicaction.js? Because all the examples I see in the web iniitialize the backbone view in the application.js. – Martin Rodriguez Jul 11 '12 at 12:29
  • I like to put the bulk of my backbone code in the external js file for me (/scripts/views/events.js) and then the backbone.history.start and some of the other init code in the view page – MarkKGreenway Jul 11 '12 at 13:57
  • Ok,thanks. But what about the event's categories? Because they are nested attributes from the event model. If I do /events/1.to_json, that won't return me the categories in json format because they are in another table. And I need the categories in order to create the Backbone collection for the categories. – Martin Rodriguez Jul 11 '12 at 15:40
  • cant you just do /event/Categories.json and follow this http://stackoverflow.com/questions/4253238/ruby-array-to-json-and-rails-json-rendering adding a second fetch – MarkKGreenway Jul 11 '12 at 15:48
  • Thanks Hurricanepkt, I'll give it a try and tell you! Cheers! – Martin Rodriguez Jul 13 '12 at 02:38