RJS implementation question


#1

Why is RJS so dependant on programatic creation of Javascript?

RHTML is a great implementation in that it puts HTML first, and Ruby
second. I would have thought RJS would be the same way: a .js with ERb
helpers for generating Javascript functions.

RJS putting Javascript second means:

  • I have to learn a whole new set of commands to use Scriptaculous.
  • Developers have to constantly chase the new implementations in
    Scriptaculous.

Am I missing something? Is there a compelling reason for not using this?


#2

I hate writing JavaScript. It is horrible to debug. I prefer Rails
and its abstraction.

~ Ben

On 5/5/06, Sam L. removed_email_address@domain.invalid wrote:

Am I missing something? Is there a compelling reason for not using this?


Posted via http://www.ruby-forum.com/.


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Ben R.
303-947-0446
http://www.benr75.com


#3

Ben R. wrote:

I hate writing JavaScript. It is horrible to debug. I prefer Rails
and its abstraction.

That’s a preferencial choice. I like the javascript helpers but they are
just that: helpers. I think they should be there when you want to use
them, otherwise they get out of the way.

Another question, If I use a .rhtml template with all javascript, using
ERb and Javascript helpers when I want to, will the result be
automatically evaluated? Do I have to change the mime-type or something?


#4

On May 5, 2006, at 1:36 PM, Sam L. wrote:

Am I missing something? Is there a compelling reason for not using
this?

We hate writing javascript. You’re welcome to write it if you so
desire.

-Derrick S.


#5

Another question, If I use a .rhtml template with all javascript,
using
ERb and Javascript helpers when I want to, will the result be
automatically evaluated? Do I have to change the mime-type or
something?

I could be wrong, but I think you can use an rjs template and do
something like this:

page << <<-JS
// Lot’s of javascript, with maybe some Ruby #{} stuff !
JS

-Derrick S.


#6

Sam L. wrote:

Why is RJS so dependant on programatic creation of Javascript?

RHTML is a great implementation in that it puts HTML first, and Ruby
second. I would have thought RJS would be the same way: a .js with ERb
helpers for generating Javascript functions.

RJS putting Javascript second means:

  • I have to learn a whole new set of commands to use Scriptaculous.
  • Developers have to constantly chase the new implementations in
    Scriptaculous.

Am I missing something? Is there a compelling reason for not using this?

Also I want to say that html and js are very different beasts. HTML is
a markup language, JS is a scripting language. You can use a pure ruby
solution to generate html as well with builder, but most of time it just
isnt necesary.

However with javascript, it’s an ugly quirky language (at least compared
to ruby) and many ruby programmers just feel more comforatble with:

page[@some_div].visual_effect :highlight

than

$(’<%= @some_div %>’).visualEffect(Effect.Highlight);

And as long as it really works, I consider it totally badass awesome
that I don;t need to write JS directly most of the time. Of course to
get the most bang for your buck you stil need to know javascript, but
that doesn’t mean you are condemned to work in it.


#7

Sam L. wrote:

Ben R. wrote:

I hate writing JavaScript. It is horrible to debug. I prefer Rails
and its abstraction.

That’s a preferencial choice. I like the javascript helpers but they are
just that: helpers. I think they should be there when you want to use
them, otherwise they get out of the way.

Another question, If I use a .rhtml template with all javascript, using
ERb and Javascript helpers when I want to, will the result be
automatically evaluated? Do I have to change the mime-type or something?

You can use .rhtml to return javasript just fine. prototype.js will
only execute it though if the ContentType is ‘text/javascript’. So set
that header from your controller and you should be fine.