4 ms·
This seems like shoehorning a JavaScript-based web framework on top of an existing web framework, which looks like it adds a lot of work. I almost threw myself
by dogas 16y ago
This seems like shoehorning a JavaScript-based web framework on top of an existing web framework, which looks like it adds a lot of work.
I almost threw myself out the window after seeing that hard-coded HTML in a JavaScript string. How is that maintainable or even nice to look at? It's not.
Am I crazy? What is the benefit of this? With a bit of customization rails could do this out of the box without a duplicate MVC arch.
- ladon86 16y agoLet's say you're writing an app like Google Docs, which does a lot of work on the client. Before long you're going to have a real mess of Javascript variables, DOM elements and arrays of stuff, which is why it's useful to have MVC structure on the client as well as the server. Your server models sync automatically to your client models, you can hit model.save() to persist your client models, and your client views represent the data in a way which can be quickly adapted if requirements change. For a less dynamic app you don't need it.
- pdelgallego 16y agoThis is not the best example. You actually don't need to hardcode the html in the javascript. You can use a template system that is already included in backbone, or you can preform a request to the server, I prefer the first approach.
- ankimal 16y agoBackbone has built in support for templating. All you have to do is tell your View object what template it needs to render and you're on your way. Obviously, you can use whatever you are comfortable with: mustache, underscore, jTemplates etc.
- bricestacey 16y agoOr you can hardcode them using CoffeeScript's heredoc syntax.
- jamesjyu 16y agoActually, in the tutorial, I go through how you can use Underscore templates, which are stored as .jst files alongside your regular ERb templates. (no hardcoded strings) I can tell you know that after using Backbone for a largish javascript project, it really eases the pain that comes with syncing data to and from the server, and handling all the random bits of javascript that usually pile up in a Rails application. Basically, it gives you a logical place for everything. Of course, if you're app isn't javascript intensive, there's no reason to use it.