RJS is Evil
This is based purely on emotion and frustration, but of all of the evil black magic in Rails, RJS is the grand daddy ruling overload of all lesser magic. There are many crimes, but the big ones are:
- Since it auto generates code, you can't search for the JS method names in your source tree.
- Since it's the reply to an AJAX request, you can't view source to see what it has generated.
- So far I've seen a lot of people use it for visual effects, and style logic, and since it's declared in your views often, it thoroughly contaminates the nice separation of concern Rails otherwise has going for it.
Rails kicks all sorts ass in a dozen different departments, but debugging other people's code that uses RJS has been consistently perplexing, difficult, frustrating and very time consuming.
It takes extra time to structure your HTML and CSS to allow you to write an entirely separate JS behavior layer. But once you do, your app will be cleaner, easier to debug, and a lot more maintainable.
Replies to this Post
Regarding point #2, have you tried firebug?
Posted June 7th, 2007 at 10:55pm by beathyate
ryan, i totally agree with you on this point. as a front-end developer, something has always bothered me about back-end code generating front-end javascript. having all of the JS in one place and using a behavior layer may not be as hip and quick, but at least you know where/when all the magic happens. then again, maybe the use case has not yet reared its ugly head.
Posted June 19th, 2007 at 8:33am by justin
Nice blog!
Some of the obfuscation can be mitigated by shunning the built in helper methods for RJS out to Scriptaculous and Prototype by using the << method instead for sending JS calls back to the client for eval "in the clear". Admittedly, a much better approach is to use the .call and .assign methods in your RJS templates, or in-line via render :update, to invoke pre-existing JS functions already loaded by the client.
As for navigating the source, I emphatically agree that it would be really nice if the in-memory tools like DOM Inspector or Firebug allowed you to snapshot the in-memory DOM as a text file instead of using the arrows to step through the tree. I find this extremely tedious, but I do appreciate the additional detail those types of tools provide over a static check of the source.
Posted July 20th, 2007 at 4:52pm by techorb
Posted October 21st, 2007 at 5:34am by
I only use a little bit of RJS at CribQ, partially out of ignorance, partially out of wanting to learn js better, and partially for the reasons you mention.
However, if you use Firebug, it is dead simple to view the generated code.
Posted December 17th, 2007 at 12:36pm by alexn
I only use a little bit of RJS at CribQ, partially out of ignorance, partially out of wanting to learn js better, and partially for the reasons you mention.
However, if you use Firebug, it is dead simple to view the generated code.
Posted December 17th, 2007 at 12:36pm by alexn
Login or Register to Post