Using Lightview with Rails 3

We use Lightview quite a bit in our websites, mostly because it has proven (to us anyway) to be an extremely flexible and easy to use lightbox script. For those that are unfamiliar with what I am referring to, lightbox scripts are nice little JavaScript libraries that allow you to display content in a “light box”, or a small window in front of your website. You see these a lot, where you click a link and your browser window will fade out a bit and display content in the foreground. If you are a developer that is interested in using this type of thing, we highly encourage you to check out all the options, and then take a hard look at Nick Stakenburg’s Lightview.

So, with the introduction out of the way, those of you using Rails 3 may experience an issues where you try to use it in a Rails application, and you get a JavaScript error that says “Lightview requires Scriptaculous >= 1.8.2”. Of course, this only applies to those developers that are using the Protoype library. At the time of this writing, I do not believe that there is a jQuery version of Lightview available, but we are looking forward to when that does become available.

Anyway, when you look at the javasripts/effects.js file, you notice that Rails 3 is using Scriptaculous 1.8.3. So what is the deal? After checking quite a few forums where developers simply decide to give up on Lightview and Prototype, I found a simple solution. In fact, so simple that I had to post about it because I imagine that a lot of people are running into this problem. And the solutions is (drum roll, please)

Paste the follow piece of code at the top of your javascripts/effects.js file: var Scriptaculous = { Version: '1.8.3' };

That’s right, it’s that simple. This simply tells Lightview that you are using version 1.8.3 (update to suit for future versions) of Scriptaculous, and that everything is fine. Once you do this, everything appears to work as it should. Many thanks to Nick Stakenburg for the Lightview library, and to any developers out there that are using it we highly recommend that you make sure that Nick is compensated for his work.

Brian Getting

Published by Brian Getting on Thursday, December 9, 2010.
Subscribe to our blog RSS feed.