Forum: Ruby on Rails RJS implementation question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Sam L. (Guest)
on 2006-05-05 21:36
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?
Ben R. (Guest)
on 2006-05-05 21:42
(Received via mailing list)
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
Sam L. (Guest)
on 2006-05-05 21:48
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?
Derrick S. (Guest)
on 2006-05-05 21:51
(Received via mailing list)
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.
Derrick S. (Guest)
on 2006-05-05 23:18
(Received via mailing list)
> 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.
Alex W. (Guest)
on 2006-05-06 00:57
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.
Alex W. (Guest)
on 2006-05-06 01:04
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.
This topic is locked and can not be replied to.