Question

I'm a new in backbone.marionette. I read some guides, but not enough understood how is the MVC structure implemented there.

In rails I'm having structure like this:

app/
  assets/
  controllers/
  models/
  views/
config/
  environmrnts/
    development.rb
    staging.rb
    production.rb
  routs.rb
log/

my view/js files are sending data to controller(during update/create and more), and and also getting data from it. the controller sends requests to model in another rails app, using Api class(that all the models are inherit from it) with net/https.

My questions are:

1. How do I implement the connection with the other app in backbone.marionette?

2. Is the idea of the mvc is the same as in rails? what actually the controller does in marionette?

3. How should my app structure look like?

4. Where should I store config parameters?

Was it helpful?

Solution

  1. It goes through the API you define in the Rails app. Each Backbone model will define a url property to indicate where its data is stored. Then Backbone will take care of the rest (e.g. sending a POST request to the API to create a new model instance in the DB)
  2. The idea is similar, but not the same. In Backbone, the controller and model behave mostly as in Rails apps. Collections are a group of models that you work with to make it easier in your app (e.g. displaying a list of users). Templates are sort of like views in Rails : they define the HTML markup that will get generated. Views in Backbone are very different : they react to the environment (e.g. user clicks, data modification) and drive the app's behavior. This doesn't happen in Rails apps because the page gets rendered and sent back : there is no itnteraction (eacch user click will make the server generate a new page and send it to the user).
  3. It depends. There are many valid approaches, and you can see one here : https://github.com/davidsulc/marionette-gentle-introduction
  4. It depends :-) Quite often, you will stroe them in a simple javascript object.

If you want something to guide you on your journey learning to develop javascript apps, take a look at these :

  • backbonerails.com uses Rails and Marionette to develop an application
  • my book on Marionette focuses more on explaining the various bits and pieces of Marionette, as well as how and when to use them

You can see an example of connecting to a different service using an API here : http://www.backbonerails.com/screencasts/loading-views starting at the 6:00 mark. The url property is defined at 9:40, but note that this case requires the url to be different for each collection instance, which might not be true in your case. If all collection instances have the same url, you'd simply define it as a property on the collection "class".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top