Announcing UJS Rails Plugin 0.3 21 August 2006
Dan and I are pleased to announce the biggest release of the Unobtrusive Javascript for Rails plugin – now simply known as UJS. This is a big release in many ways – we’ve got some important bug fixes in here, some great new helper functionality and most importantly: caching.
Here is the changelog for 0.3:
- FIXED: Problems with rake:unobtrusive_javascript:install (ticket #12 on old trac)
- FIXED: Problems with back button (result of caching feature) (ticket #10 on old trac)
- Refactored a lot of the code and increased test coverage significantly
- NEW: Out-of-the box caching using HTTP ETags and advanced behaviour caching
- NEW: Apply multiple behaviours at once with apply_behaviours
- NEW: Behaviour helpers to easily and unobtrusively apply scriptaculous effects
- UPDATED: Updated lowpro.js library
- UPDATED: Added :external option support to tag_options
- NEW: :prevent_default option to cancel original event behaviour such as link following and form submission
The other big change is that the Subversion repository has changed location, as has the place to report issues with the plugin: the plugin now has its own dedicated Trac.
The plugin repository is now located at:
The latest version of the plugin now has its own tag, which should make it work with Rails’ built-in script/plugin script:
http://source.ujs4rails.com/current/unobtrusive_javascript
Finally, you can report issues on the UJS Rails Plugin Trac:
You can also find updated RDoc documentation at http://docs.ujs4rails.com
Important Note: If you are running on Edge Rails, the plugin will only work if you freeze to revision 4727. This is due to issues with the new Rails dependencies system. The plugin works fine on Rails 1.1.6.
If you’ve not yet used the plugin, now is the time to check it out. Grab the latest release and get started!
1. Comment by Jeroen on 21 Aug 2006 at 17:08
So can we use this with the latest stable rails (1.1.6) ?
2. Comment by Dan on 21 Aug 2006 at 17:08
Yes, I’ve been using it with 1.1.6. However, it suffers from the same problem that many plugins do with edge rails but I’m sure core will get this fixed soon.
3. Comment by Luke Redpath on 21 Aug 2006 at 18:08
I just realised that my note about edge rails wasn’t very clear – I’ve updated this. It should work fine with 1.1.6, and edge up to revision 4727.
4. Comment by brasten on 21 Aug 2006 at 18:08
This looks really great, however I do have more of a development-style question:
I felt that one of the greatest benefits to using something like event:Selectors was that your content and behavior could reside in separate files. I understand that from the browser’s view that is what UJS is doing, but it appears that separation no longer exists from the developer’s point of view, and you’re still adding JS-helper methods directly into the view templates.
So my question is two-fold: a) am I misunderstanding how one should use UJS, and; b) if not, have I been putting too much importance on that separation from the developers point of view? Is the best-practice in this case really to keep your behavior and view code together?
Let me know if I’m off-base here! Thanks!
5. Comment by Dan on 21 Aug 2006 at 20:08
brasten, unobtrusive scripting is not necessarily about seperate files, although, you do gain advantages, such as browser caching, from this. Unobtrusive scripting is more about separating out the ‘behavior’ layer from the content and the styling of your document so that the behavior is an enhancement to an otherwise operational application. It’s primarily a separation of concerns rather than a separation of files.
However, when writing an application many Rails developers are more comfortable with dealing with the whole of the UI in the view file.
If you prefer to work with seperate files you can write your behaviour into reusable helper methods.
6. Comment by Luke Redpath on 21 Aug 2006 at 23:08
brasten – to add to Dan’s comments, whilst it is important to have your behaviours separate from your content from the browsers point of view, from a developers point of view I find it easier to have the behaviours close to the elements that they apply to – that way it is much easier to get a good overview of how your page works without having to open up and search through another file.
7. Comment by Frederick Cheung on 22 Aug 2006 at 13:08
Looks very interesting stuff ineed.
My main concern so far is that it seems to change remote_function so that the javascript is no longer escaped.
I can see why you do this in the context of UJS, however my project uses remote_function in other places and just installing the plugin broke those places, having to move everything over in one go is a bit of a barrier to use.
Overall looks very interesting (and I look forward to seeing your presentation at RailsConf)
8. Comment by Dan F on 22 Aug 2006 at 14:08
When I first started using JavaScript in Rails, I wanted to use behaviour.js to avoid adding inline JS to HTML pages.
I really liked the concept but eventually was faced with the following problem: behaviours could only be applied once the whole page was loaded. Inline JS, on the other hand, kicks in as soon as the browser loads the elements and their inline JS statements.
Am I going to have the same problem with UJS?
9. Comment by Luke Redpath on 22 Aug 2006 at 14:08
Dan F – I’ve got good news for you – no you aren’t.
Instead of using window.onload, the lowpro library applies behaviours to elements as soon as they are available in the DOM (so before the page, including images, has fully loaded).
10. Comment by Luke Redpath on 22 Aug 2006 at 14:08
Frederick – we aren’t explicitly changing the way js is escaped as far as I’m aware so this sounds like an unwanted side effect. Could you file a ticket with more details? Obviously we want to keep the barrier of entry as low as possible and this includes not breaking people’s existing apps.
11. Comment by Frederick Cheung on 23 Aug 2006 at 09:08
Just filed a ticket. Turns out I wasn’t quite correct:, before UJS remote_function produces js that uses single quote to delimit strings, so I can happily include it in double quotes, but post-UJS remote_function uses double quotes
12. Comment by Dan Webb on 25 Aug 2006 at 20:08
Ah, my fault. No problem, I’ll get that fixed.
13. Comment by Adam Craven on 28 Aug 2006 at 01:08
Is there a zip/rar/gzip of this? The idea of downloading the files individually isn’t very appeasing.
14. Comment by Luke Redpath on 28 Aug 2006 at 01:08
Adam – the plugin is designed to be checked out of Subversion directly into your Rails plugins directory. Just use svn co.
15. Comment by Adam Craven on 28 Aug 2006 at 13:08
Thanks Luke, I better get up on SVN, seems it’s being used everywhere nowadays.
When coming to rails, it’s been an amazing experience how great it is. Unfortunately, being an accessibity advocate (unobstrusive and graceful degradation), it’s a shame to see so much script generated at the front end, which is not only not needed, but also your program doesn’t work by default if javascript isn’t enabled. However, with that said, it’s not hard to add your own libaries in.
Keep up the good work.
16. Comment by Josh Adams on 06 Sep 2006 at 17:09
A couple of things.:0xb757685c>
1) The quickstart suggests adding UnobtrusiveJavascript::routes to your routes.rb when it seems that I should instead add UJS.routes. I filed a bug against the site.
2) I’m getting this error: undefined method `set_default_external!’ for #<#
Don’t know if it matters, but I use markaby for all my layouts. I’ll file a bug against this now as well.