

How Rails Developers do Ajax in 2011 - chadfowler
http://chadfowler.com/2011/2/9/how-rails-developers-do-ajax-in-2011

======
glasner
I wrote a small wrapper on top of backbone and Backbone.Rails.js [1]. The
combo replaced a very bulky internal framework, and I would never go back.

[1] <https://gist.github.com/719080>

------
fphilipe
Before I started developing Rails I always used JSON + client side templates
which were constructed in pure jQuery and really tedious.

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.

------
bherms
Could anyone share some good tutorials or guides on getting started with
(preferably jQuery) AJAX and Rails 3?

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.

~~~
anonova
I'd also be interested in some up-to-date guides on this. I've always used the
.js.erb method Fowler talks about because it's what I see Ryan Bates do in his
Railscasts (the last screencast Bates used this method is in [#240][1]).

[1]: [http://asciicasts.com/episodes/240-search-sort-paginate-
with...](http://asciicasts.com/episodes/240-search-sort-paginate-with-ajax)

------
zzzmarcus
Is anyone using pure.js? That's been one on my radar since they use pure HTML
templates with JSON models. I don't think it does data binding to update the
template automatically after the first render if the model changes, but apart
from that, it seems preferable to using custom templates like jQuery or
Mustache etc.

<http://beebole.com/pure/>

That having been said, I haven't started using it yet. I'm open to other
viewpoints.

~~~
tchvil
I wrote it. What makes jQuery and Mustache preferable? I know pure.js is
different, but having the HTML clean of any tags or logic is something new and
very flexible.

~~~
zzzmarcus
That's what I was saying. From what I've seen, pure.js does seem preferable to
using Mustache or jQuery templates. I was curious if anyone else had other
feedback after using it.

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? :)

~~~
tchvil
I guess people feel at home with a double-brackets template engine. It mimics
what exist server side for ages. A pity as HTML in the browser is a DOM, not a
sliced string.

------
minalecs
I like to use a combination of these. There is no wrong way or right way, just
the way that gets you done fast, and maintainable. You may begin using one way
and find it may be easier trying another way, depending on what you're trying
to do. The great thing is the flexibility.

------
catshirt
why suffer the performance implications of client side rendering for something
like partials?

~~~
_pius
Wouldn't the right question be "why suffer the performance implications of
_server_ side rendering for something like partials?"

~~~
Semiapies
Accessibility, for one.

~~~
kls
I see this one come up time and time again, Accessibility is not implicit to
server side rendering and is easily managed via client side rendering. It is
one of my companies specilizations we do client side web app accessibility and
to be honest building an accessibility layer with client side logic is far
easier than dealing with it via the degree of separation that the server
creates. There are many tricks that we use to fool JAWS into doing what we
want that are just not available via server side rendering. Accessibility is
not hindered by client side rendering if anything it can be enhanced.

