Reputation: 7227
I am working on a app that has multiple types of users, each user has a separate view when they are logged in. for example a business type user will create his profile upload photos etc, create some other stuff. and then the content created by businesses is visible public on the web-app's landing page.
I am using backbone on the client side, but the whole web app isn't all backbone, the business management area is a separate part which a backbone app runs on the client side, and now I am looking to start on the public landing page, I am confused on how to make this work, should I create a new backbone app for this page, or stuff more views models and collections into the same app?
The urls of both pages differ one is like whatever.com/business and the landing page is at whatever.com
Many views and models from the business side are the same as needed on the public landing page. But I can't think of a good solution on how to organize this.
Has any one worked on something like this before. Any insights ?
Thanks
Upvotes: 2
Views: 525
Reputation: 28245
There are two excellent (pro) Railscasts on this topic, #323 Backbone on Rails Part 1 and #325 Backbone on Rails Part 2, unfortunately they are behind a paywall, but the money is worth it. Ryan uses the backbone-on-rails gem to facilitate the integration of Backbone into Rails.
It is recommendable to do the whole MVC processing either in Rails (mainly in the backend, with a bit of Ajax and without any Backbone) or in Backbone (mainly in the frontend, using Rails only as a storage engine). Selecting Backbone or similar MVC JS frameworks like ember.js is useful if your application consists mainly of Javascript or JQuery calls, or if you want to do realtime web apps and live page updates. Since it is not sure if MVC Javascript frameworks are really technically mature yet, I would recommend to stick with pure Rails if you do not trust that Backbone can handle all your requirements.
An interesting idea for a general architecture is to use a JSON API as a connection between Rails backend and JS MVC frontend, which means the backend can push the same JSON to the webpage as it does to the iOS and Android apps.
Upvotes: 2
Reputation: 38418
Backbone.js is a great MVC framework but there isn't a whole lot of convention around organising a large application. You need to be familiar with some good design patterns to get the most out of it or it quickly gets messy.
I was looking at AMD earlier. It looks nice:
http://backbonetutorials.com/organizing-backbone-using-modules/
THis might help too:
http://ricostacruz.com/backbone-patterns/
I also enjoyed this rule book on designing a good API. It was only $8 on my kindle!
http://www.amazon.com/REST-API-Design-Rulebook-ebook/dp/B005XE5A7Q
Edit: I recently refactored a large backbone.js application. I found it a lot easier to build if I exploited Javascript event driven architecture.
Upvotes: 3