Impressed with Rails – again

So, I had need of a little ‘Ajax’. I wanted to provide a brief preview of some content, but without all the nastiness of page refreshes – an ideal candidate for XMLHTTPRequest. So I wrote my own. That was a mistake.

I’m comfortable with Javascript – I think I’m fairly accomplished with it – so I got it done, and it worked. It was only then that I thought ‘I think Rails does Ajax too’. Does it ever! Ten minutes, and I had a Rails Ajax version working (a lot less than my own time, even with my boiler-plate code) and, and this is the best bit, much more readable code! That’s what I call a win. link_to_remote was the useful function in question, and my call is:
link_to_remote( "Show",
:url => { :action => "show_small", :id => },
:update => "js_board",
:before => "document.getElementById('js_board').style.left = get_x(this);
document.getElementById('js_board') = get_y(this)",
:complete => "document.getElementById('js_board').style.visibility = 'visible'" )

Impressed with Rails – again

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.