I'm struggling to understand the proper usage of Rails JS templates. Are they essentially replacing the success callback on an AJAX request? Why separate the JavaScript executed for a successful request from that of other callbacks?
My assumption is that I am attaching a click handler to a link and triggering an AJAX request in this scenario. Alternatively, I could use a link_to
with :remote => true
, which might justify using JS templates. But how do you handle cases other than success? Should I bind an ajax:failure
event to the generated link? This would mean maintaining JS related to the link in two different places. What if there are two links (each with different markup) that both make requests to the same action but require different JS execution based on how they need to behave when clicked? How can a JS template address this complexity?
Am I approaching this issue correctly?