Where did UJS go? UJS vs. RJS

I think minus_r plugin is the way to go, developers should learn javascript anyway so why make a duplicate in ruby for a couple of functions.

Yitzhak Bar Geva wrote:

Really? I'm devoting a lot of time and effort to learning Ruby and Rails as it is. I really don't want to bother with Javascript coding if I don't have to and I seem to see that many other Rails developers do likewise. Isn't that so?

I think you’ve got your acronyms switched up. UJS and RJS are not interchangeable systems. UJS (Unobtrusive JavaScript) is for hiding away the “new Ajax.Upater(…)”, etc calls into a .js file instead of filling up the HTML source with the mess. It also helps to make sure your site works with JS turned off.

RJS is a system that lets you send back javascript code responding to an AJAX call that then gets executed immediately upon receipt.

UJS vs RJS? That question makes absolutely no sense.

As for minus_r, meh. What RJS gives you is the “guarentee” that the javascript generated will be cross-browser compatible when such situations may arise. Minus_r puts that burden on the developer.

Jason

Thank you for the clarification. I'm busy learning Rails right now with the new second edition of Agile Web Development with Rails. UJS isn't in the book. It was too new. I see a lot of people using it. My question then is, should I as a newbie start by using UJS from the outset? Also, where did it disappear to?

Jason,

RJS does nothing more than use the javascript lib's that are already cross-browser compatible. Minus_r doesn't put that burden on the developer if you use lib's that are cross platform (like my favorite lib jquery).

Don't you ever use javascript besides rjs? never define javascript in application.js?

Jason Roelofs wrote:

yitzhakbg wrote:

Really? I'm devoting a lot of time and effort to learning Ruby and Rails as it is. I really don't want to bother with Javascript coding if I don't have to and I seem to see that many other Rails developers do likewise. Isn't that so?

The relationship between Rails and Javascript resembles that between C and Assembler in the 1970s. Back then, you had to know Assembler to use C, not least because you had to debug things when they went wrong.

Someday our Javascript will be transparent, and all the fun we have with it today will be a pleasant nostalgia. Until then, learn JS, from the bottom up, and then do everything you can to use Ruby to avoid writing any. Same as with C and Assembler.

I like the analogy Phlip.

yitz: While prototype.js and scriptaculous.js may be cross browser, but those libraries don’t do everything. If you’re writing JavaScript by hand, you are risking cross-browser incompatibilities, it’s just the nature of the language today. You ask if I’ve ever written any by hand: Yes, I have. In fact, I’m working on a browser-based Rogue-like RPG and have a fully unit-tested base of JavaScript code to work with now, all written from scratch. I’ve taken the stance currently to only work with Firefox and to deal with cross-browser issues later, though at the same time trying to stay with techniques that already work everywhere. Yes I know how to write JS, I know what it entails, and frankly I’d prefer not to if I can, and with Rails, RJS lets me stay away from JS and stay with Ruby, which I am always happy to write.

Jason

Sorry, the above is pointed to Adbur, not Yitz.

Jason

JavaScript is primarily used for browser side scripting today. So far, at least until the Sun Scripting engine with JRuby is released, browser side ruby is non-standard.

In a typical "real-life" application, I will use six or more distinct identifiable programming languages (COBOL, SQL, Java, XSLT, HTML, JavaScript). For me, Ruby fits into the same slot as Java+XSLT.

IMHO, another language is not that much of a burden.

Jason Roelofs wrote:

> The relationship between Rails and Javascript resembles that between C > and Assembler in the 1970s. Back then, you had to know Assembler to > use C, not least because you had to debug things when they went wrong.

I like the analogy Phlip.

And you try to tell that to these youngsters today, and they wu-oun't believe you!

yitz: While prototype.js and scriptaculous.js may be cross browser, but those libraries don't do everything. If you're writing JavaScript by hand, you are risking cross-browser incompatibilities, it's just the nature of the language today. You ask if I've ever written any by hand: Yes, I have. In fact, I'm working on a browser-based Rogue-like RPG

Hex-shaped?

and have a fully unit-tested base of JavaScript code to work with now, all written from scratch.

Automated unit tests? How? out of curiousity...

Thank you folks for the background. In fact I was an accomplished C and Assembler programmer for many years. Presently however, I'm so immersed in learning material related to Ruby On Rails, CSS, telephony server AVR and VXML material that I'd be happy to keep JS off the list if I could. I feel somehow in the course of this discussion, that my questions about UJS got lost somewhere.. Happily the UJS site is back on the air and I now understand that UJS is not a replacement for RJS. What is not clear to me is whether it can help make a developer's life easier. Is it's use recommended? What's the bottom line?

yitzhakbg wrote:

Thank you folks for the background. In fact I was an accomplished C and Assembler programmer for many years. Presently however, I'm so immersed in learning material related to Ruby On Rails, CSS, telephony server AVR and VXML material that I'd be happy to keep JS off the list if I could. I feel somehow in the course of this discussion, that my questions about UJS got lost somewhere.. Happily the UJS site is back on the air and I now understand that UJS is not a replacement for RJS. What is not clear to me is whether it can help make a developer's life easier. Is it's use recommended? What's the bottom line?

>

Just to add my $0.02. I think UJS is excellent -- mostly for the way it separates the js from the HTML. I'm not a professional programmer (though as a spotty teenager 20-odd years ago I taught myself assembly and even machine code), and I find that, like rails, it helps push you in the direction of doing things in an elegant way.

Get the non-js functionality right, add the Ajax functionality via UJS, and you have clean, gracefully degrading code that is easier to understand, debug, refactor and may well be smaller too.

I’ve taken the javascript_test plugin (http://dev.rubyonrails.org/svn/rails/plugins/javascript_test/ ) and modified it to use JsUnit instead of Scriptaculous’s unittest.js. I’ve been meaning to clean this up and publish it. Basically a Rake task sets up a Webrick server, mounting the appropriate paths, and then opens up a browser of your choice at the javascript test url. If you want to check out what I’ve got vs javascript_test feel free to drop me a line and I’ll send it to you.

Jason