# \[ANN\] Unobtrusive Javascript for Rails

**URL:** <https://www.ruby-forum.com/t/ann-unobtrusive-javascript-for-rails/62650>\
**Category:** Rails\
**Created:** [June 7, 2006, 12:24am UTC](https://www.ruby-forum.com/t/ann-unobtrusive-javascript-for-rails/62650 "2006-06-07T00:24:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![lukeredpath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@lukeredpath](https://www.ruby-forum.com/u/lukeredpath)\
**Post date:** [June 7, 2006, 12:24am UTC](https://www.ruby-forum.com/t/ann-unobtrusive-javascript-for-rails/62650/1 "2006-06-07T00:24:25Z")

</div>

I made a brief post on here the other day about this and now I can  
proudly present the initial release of our unobtrusive\_javascript  
plugin for Rails. We’ll be working with Dan W. of Vivabit to roll in  
much of the functionality in his own as-yet unreleased  
unobtrusive\_javascript plugin into a single plugin.

This is essentially a preview release and probably not suitable for  
use on a production site just yet but we hope it will be production  
ready ASAP.

So here’s the important details!

The blog post:  
[http://www.lukeredpath.co.uk/index....ript-for-rails/](http://www.lukeredpath.co.uk/index....ript-for-rails/)

The documentation/information:

> **[AgileEvolved.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=agileevolved.com)**
>
> Own this domain today. We make your shopping experience easy. Friendly and quick customer service.

The source:  
[http://opensource.agileevolved.com/...avascript/trunk](http://opensource.agileevolved.com/...avascript/trunk)

All comments and ideas are welcome. Enjoy!

\*\* Apologies if this ends up here twice but gmail is acting up

---

<div class="post-metadata">

**Author:** ![lukeredpath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@lukeredpath](https://www.ruby-forum.com/u/lukeredpath)\
**Post date:** [June 7, 2006, 11:27am UTC](https://www.ruby-forum.com/t/ann-unobtrusive-javascript-for-rails/62650/2 "2006-06-07T11:27:46Z")

</div>

Sorry, here’s the fixed URLs:

The blog post:  
[http://www.lukeredpath.co.uk/index.php/2006/06/06/introducing-unobtrusive-javascript-for-rails](http://www.lukeredpath.co.uk/index.php/2006/06/06/introducing-unobtrusive-javascript-for-rails)

The documentation/information:

> **[AgileEvolved.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=agileevolved.com)**
>
> Own this domain today. We make your shopping experience easy. Friendly and quick customer service.

The source:  
[http://opensource.agileevolved.com/svn/root/rails\_plugins/unobtrusive\_javascript/trunk](http://opensource.agileevolved.com/svn/root/rails_plugins/unobtrusive_javascript/trunk)

---

<div class="post-metadata">

**Author:** ![lukeredpath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@lukeredpath](https://www.ruby-forum.com/u/lukeredpath)\
**Post date:** [June 7, 2006, 3:35pm UTC](https://www.ruby-forum.com/t/ann-unobtrusive-javascript-for-rails/62650/3 "2006-06-07T15:35:00Z")

</div>

Very very cool.

---

<div class="post-metadata">

**Author:** ![lukeredpath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@lukeredpath](https://www.ruby-forum.com/u/lukeredpath)\
**Post date:** [June 7, 2006, 3:35pm UTC](https://www.ruby-forum.com/t/ann-unobtrusive-javascript-for-rails/62650/4 "2006-06-07T15:35:37Z")

</div>

I get invalid links for those… 404 for the first, and nothing useful  
for the other two.  
Is it just me?

---

<div class="post-metadata">

**Author:** ![lukeredpath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@lukeredpath](https://www.ruby-forum.com/u/lukeredpath)\
**Post date:** [June 7, 2006, 4:42pm UTC](https://www.ruby-forum.com/t/ann-unobtrusive-javascript-for-rails/62650/5 "2006-06-07T16:42:57Z")

</div>

Hello,

I too am having a problem with this plugin. I found the  
event-selectors.js file in the assets folder of the plugin and put it  
into the “public/behaviours” folder which worked for it but I am getting  
an error when it looks for dynamic.js in the same location. I am using  
the latest version of Prototype. The exact errors I am getting (in  
Firefox 1.5.0.4) is “EventSelectors is not defined.” Thank you for your  
help.

Sincerely,

Robert D.

---

<div class="post-metadata">

**Author:** ![lukeredpath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@lukeredpath](https://www.ruby-forum.com/u/lukeredpath)\
**Post date:** [June 7, 2006, 6:40pm UTC](https://www.ruby-forum.com/t/ann-unobtrusive-javascript-for-rails/62650/6 "2006-06-07T18:40:51Z")

</div>

Robert D. wrote:

> Hello,
> 
> I too am having a problem with this plugin. I found the  
> event-selectors.js file in the assets folder of the plugin and put it  
> into the “public/behaviours” folder which worked for it but I am getting  
> an error when it looks for dynamic.js in the same location. I am using  
> the latest version of Prototype. The exact errors I am getting (in  
> Firefox 1.5.0.4) is “EventSelectors is not defined.” Thank you for your  
> help.
> 
> Sincerely,
> 
> Robert D.

Hi Robert - there is no need to copy anything into your public folders -  
both the event-selectors.js and dynamic.js contents are rendered at  
runtime by a built-in controller that comes with the plugin.

There was a bug where the controller action responsible for rendering  
the contents of event-selectors.js was looking for it in the wrong  
place. I fixed this earlier so please run an update and have another go.

Cheers  
Luke

---

<div class="post-metadata">

**Author:** ![lukeredpath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@lukeredpath](https://www.ruby-forum.com/u/lukeredpath)\
**Post date:** [June 7, 2006, 8:29pm UTC](https://www.ruby-forum.com/t/ann-unobtrusive-javascript-for-rails/62650/7 "2006-06-07T20:29:20Z")

</div>

Luke,

That fixed the problem. Thank you very much for such a quick fix. Works  
like a charm! I intend on using it asap. Much obliged.

- Robert D.

Luke R. wrote:

> Hi Robert - there is no need to copy anything into your public folders -  
> both the event-selectors.js and dynamic.js contents are rendered at  
> runtime by a built-in controller that comes with the plugin.
> 
> There was a bug where the controller action responsible for rendering  
> the contents of event-selectors.js was looking for it in the wrong  
> place. I fixed this earlier so please run an update and have another go.
> 
> Cheers  
> Luke

---

<div class="post-metadata">

**Author:** ![lukeredpath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@lukeredpath](https://www.ruby-forum.com/u/lukeredpath)\
**Post date:** [June 9, 2006, 9:17am UTC](https://www.ruby-forum.com/t/ann-unobtrusive-javascript-for-rails/62650/8 "2006-06-09T09:17:37Z")

</div>

Hi Luke

I like the idea of this plugin very much. However, I have no luck  
getting it to work. Here’s what I’m trying to do:

I have a partial that renders several boxes containing some text. Each  
box is in a div with a unique id like this:

... \</div

I would like to apply some effect for a mouseover and I tried it like  
this:

\<% register\_js\_behaviour “#entry9:mouseover”, visual\_effect(:highlight,  
“entry9”, :duration =\> 0.5) %\>

The selector is hardcoded for testing purposes and there is a div with  
id “entry9” on the page. But nothing happens ☹ What am I doing wrong  
here ?

The prototype-scripts are installed and working, I am using effects in  
my rjs-files.

Any help would be very appreciated

Best regards

Gernot

---

<div class="post-metadata">

**Author:** ![lukeredpath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@lukeredpath](https://www.ruby-forum.com/u/lukeredpath)\
**Post date:** [June 9, 2006, 12:44pm UTC](https://www.ruby-forum.com/t/ann-unobtrusive-javascript-for-rails/62650/9 "2006-06-09T12:44:11Z")

</div>

Hi Gernot,

I’m not sure why it isn’t working - can I advise you to try loading up  
your page in Firefox using the Firebug extension? You’ll be able to  
select the dynamic.js file and view the javascript that has been  
generated.

Once you’ve tried this, please submit a bug on our Trac at

> **[AgileEvolved.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=agileevolved.com)**
>
> Own this domain today. We make your shopping experience easy. Friendly and quick customer service.

Cheers  
Luke

Gernot K. wrote:

> Hi Luke
> 
> I like the idea of this plugin very much. However, I have no luck  
> getting it to work. Here’s what I’m trying to do:
> 
> I have a partial that renders several boxes containing some text. Each  
> box is in a div with a unique id like this:
> 
> ... \</div
> 
> I would like to apply some effect for a mouseover and I tried it like  
> this:
> 
> \<% register\_js\_behaviour “#entry9:mouseover”, visual\_effect(:highlight,  
> “entry9”, :duration =\> 0.5) %\>
> 
> The selector is hardcoded for testing purposes and there is a div with  
> id “entry9” on the page. But nothing happens ☹ What am I doing wrong  
> here ?
> 
> The prototype-scripts are installed and working, I am using effects in  
> my rjs-files.
> 
> Any help would be very appreciated
> 
> Best regards
> 
> Gernot
