June 14, 2006

Posted by John

Tagged rjs

Older: Using App Guts in Your Plugins

Newer: Railsday SVN

RJS Class Proxies

You might already know that you can call the following from an RJS template …

page.form.reset('some-form')

to generate the following Javascript code …

Form.reset("some-form");

This works because Form is a class in prototype which is bundled with Rails. However, did you know that the RJS class proxy will also work with your own included Javascript classes?

Let’s say you have the following Javascript class …

var Message = {
  say:function(text) {
    alert('You just said: ' + text);
  }
}

I just learned tonight that you can call this in RJS like so …

page.message.say('I love RJS!')

which would produce …

Message.say('I love RJS!');

Man is that cool.

0 Comments

Thoughts? Do Tell...


textile enabled, preview above, please be nice
use <pre><code class="ruby"></code></pre> for code blocks

About

Authored by John Nunemaker (Noo-neh-maker), a programmer who has fallen deeply in love with Ruby. Learn More.

Projects

Flipper
Release your software more often with fewer problems.
Flip your features.