Mixing backbone.js routers and rail controllers

I'm currently trying to wrap my head around the backbone.js vaccination in my rails application. First, I want to create it in a specific part of the rails application in / application. With that said, I have a resource resource "resources: applications", which gives me localhost: 3000 / applications. Now, when I create the basis for / applications, I get anchor tags for trunk routing on this rail resource. IE localhost: 3000 / applications / # applications / 5.

Given that I'm going to use the backbone in certain parts of the rails application, so without making it a single-page application, is this the right way to do something? The url looks a bit redundant.

The correct answer may be that I need to do away with the trunk router? If so, how is it possible: id to be transferred to the base application when trying to search for a collection / model.

A point using the trunk will help organize a specific section of the rails application, which will be heavy javascript.

I should mention that I can change the router to something like:

routes: '': 'index' ':id': 'show' 

which will give me the localhost url: 3000 / applications / # / 1 - however I think that it paints me in the corner and will not allow me to use the trunk on other rail resources. If I had localhost: 3000 / dashboard with the called base, then the incorrect function backbone.js will be executed.

Another thought would be to call a reverse router on each rails resource. I could use the above route code, since the router will only be called for this rails resource.

+4
source share
1 answer

In the end, I realized that. I switched to using the main rails and watched their tutorial to get an example application; https://github.com/codebrew/backbone-rails . The solution appeared in rails html.erb and loaded only the specific router that I need for the rails resource.

 routes: "new" : "newPost" "index" : "index" ":id/edit" : "edit" ":id" : "show" ".*" : "index" 

Then, let's say post.html.erb, I could put the following.

 <div id="posts"></div> <script type="text/javascript"> $(function() { // Blog is the app name window.router = new Testing.Routers.PostsRouter({posts: <%= @posts.to_json.html_safe -%>}); Backbone.history.start(); }); </script> 

If my answer does not make sense, I suggest going through the tutorial at the github link mentioned above.

+3
source

All Articles