Getting my application more DRY with rails and backbone.js

Okey, so I decided to go with backbone.js in my rails application, but I feel like I am doing a lot of redundant coding. I have many models and patterns in the spine that more or less match the equivalents of their rails. Is there any stone that can handle this? Something like act_as_backbonemodel that you insert into your rail model, which generates the base model (with the option of overriding to add functionality). It would also be great if there was some kind of embossed embossed pearl that allows you to put your templates in your submission catalog and use the usual partial / repeat views of regular rails.

+7
source share
3 answers

The closest Gem that I know of is: https://github.com/codebrew/backbone-rails Perhaps combined with: https://github.com/netzpirat/haml_coffee_assets

The presence of Backbone patterns in applications / views does not make sense, since they must be skinny JS (or compiled into js) files that contain (almost) no logic. You should consider downloading them from the CDN through the asset pipeline.

A common use case is that Backbone processes the front-end logic and uses Rails as soon as your API.

+1
source

When I started using Backbone with Rails (almost a year ago), I also wanted to get such a gem (at that time I used base rails). Initially, it seemed that many things were duplicated between the base and the rails, but as I developed, I found this more likely an exception than a rule. Especially if you use Rails as an API, this kind of gemstone can be useful only at the beginning of the project and is less appropriate afterwards.

I am talking about this because most of our models no longer have 1-1 matching with our Rails resources. For example, while information about people is required, this information comes from a combination of several resources and excludes a significant part of the data in the primary records of people. In addition, creating and changing them is not suitable in our application, and creation is carried out only by invitation and is fully disclosed as a separate resource.

Other resources are not needed, and at the same time, others have such a small set of functionality or data or data from several resources that really will not work with their creation.

Since rails is an API in our case, we do not have duplication at the presentation level.

I find that creating customizable generators that match the way you work with the backbone network, or having multiple templates in your selection editor, is a more flexible solution.

In terms of organization, we added the foundation as a directory in the app / assets / javascripts directory and created directories for models, views, routers, helpers, etc. here. This allows you to use coffeescript to write the basics without any gems. We use jasmine and jasminerice gems to test our base code with coffeescript and haml for fixtures (they live in the spec / javascripts} directory.

As for the templates, then all the rails consider the partial parts in our controllers, which are displayed in the header. The trunk searches for them by id and uses them from there.

Hope this helps.

+1
source

I just got information that the xing.com business community platform is creating such a stone.

look at the repository on github: https://github.com/xing/slouch

it is not yet documented, but I think it should be easy to get in touch with the guys building it.

0
source

All Articles