# RJS implementation question

**URL:** <https://www.ruby-forum.com/t/rjs-implementation-question/59723>\
**Category:** Rails\
**Created:** [May 5, 2006, 7:36pm UTC](https://www.ruby-forum.com/t/rjs-implementation-question/59723 "2006-05-05T19:36:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@sam](https://www.ruby-forum.com/u/sam)\
**Post date:** [May 5, 2006, 7:36pm UTC](https://www.ruby-forum.com/t/rjs-implementation-question/59723/1 "2006-05-05T19:36:41Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@sam](https://www.ruby-forum.com/u/sam)\
**Post date:** [May 5, 2006, 7:42pm UTC](https://www.ruby-forum.com/t/rjs-implementation-question/59723/2 "2006-05-05T19:42:15Z")

</div>

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](mailto: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/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Ben R.  
303-947-0446  
[http://www.benr75.com](http://www.benr75.com)

---

<div class="post-metadata">

**Author:** ![sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@sam](https://www.ruby-forum.com/u/sam)\
**Post date:** [May 5, 2006, 7:48pm UTC](https://www.ruby-forum.com/t/rjs-implementation-question/59723/3 "2006-05-05T19:48:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@sam](https://www.ruby-forum.com/u/sam)\
**Post date:** [May 5, 2006, 7:51pm UTC](https://www.ruby-forum.com/t/rjs-implementation-question/59723/4 "2006-05-05T19:51:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@sam](https://www.ruby-forum.com/u/sam)\
**Post date:** [May 5, 2006, 9:18pm UTC](https://www.ruby-forum.com/t/rjs-implementation-question/59723/5 "2006-05-05T21:18:33Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@sam](https://www.ruby-forum.com/u/sam)\
**Post date:** [May 5, 2006, 11:04pm UTC](https://www.ruby-forum.com/t/rjs-implementation-question/59723/6 "2006-05-05T23:04:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@sam](https://www.ruby-forum.com/u/sam)\
**Post date:** [May 5, 2006, 10:57pm UTC](https://www.ruby-forum.com/t/rjs-implementation-question/59723/7 "2006-05-05T22:57:42Z")

</div>

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.
