How Rails Developers do Ajax in 2011
chadfowler.com
chadfowler.com
Then, with Rails, I asked myself, why would I want to have the template somewhere in the middle of a JS file where it isn't even recognizable as an HTML template at first sight? Why not have it, like all the other views, in one convenient place? Furthermore, often you have a partial you render on the server side and with some AJAX you send more entities of this partial to the client. Having this partial twice is really tedious if you wan't to tweak the HTML.
I'm doing a little here and there in a current web app, but I could absolutely use some tips, pointers, and direction on better ways.
[1]: http://asciicasts.com/episodes/240-search-sort-paginate-with...
That having been said, I haven't started using it yet. I'm open to other viewpoints.
The reason I am considering it is to be able to use Ruby erb templates on the server to initially populate data on a page, then use pure.js and its directives to treat that same HTML as a javascript template.
With mustache or jquery templates and everything else I've seen, you're tied to rendering at least some basic empty HTML first, then populating it with javascript templates once javascript is ready.
I've messed around with it some and it seems to work fine. I guess my question is why isn't everyone doing it this way? :)
based on the responses it's clear that my question sounded like a leading one. it was not and i employ both methods actively.
- It means you can render partials to the user before you receive data from the server. So things seem to happen instantaneously to the user.
- It also means you can have your partials rendering in a single place and rendered by a single template engine.
performance was admittedly awfully misdirected in a general context. i suppose my situation is unique; several templates on my app require complex logic or additional requests based on properties of the initial request. this is where you start to see it get hairy.
again though, admittedly not the normal scenario. i appreciate you taking my question literally, as it was meant.