Ruby on Rails is a great platform to work with, there is so much niceties for geeks like me. Today has been a great day to work with RJS templates.
You must use RJS templates, just because when you don’t know where to put the view behavior after an action, and because filling a link_to_remote helper with too much parameters is really ugly.
Changing DOM className
Because my application needs to display some dynamic user selection of an avatar, a great way has been to change the CSS className of the selected avatar.
Here is how to do it with RJS:
page.select(".avatar").all() do |element, index|
page.call 'Element.removeClassName', element, 'selected_avatar'
end
page.call 'Element.addClassName', @avatar, 'selected_avatar'





2 comments
Comments feed for this article
Trackback link
http://blog.alexgirard.com/using-rjs-templates/trackback/
March 14, 2007 at 7:01 pm
JF0h
Have you noticed any issues with Rails 1.2 and RJS template files not getting called correctly? When I do an :update in the controller for an xmlHttpRequest, everything works. When I have an RJS file with the same calls, it never gets read. I am using link_to_remote without an :update callback specified so the method should go looking for the file.rjs instead. But it does not. This all worked fine in Rails 1.1.6. I even removed info from the RJS file and did a simple page.alert(’wtf’) and it was never accessed it appears. The log shows everything rendering with no errors but the ‘page’ isn’t updating.
March 15, 2007 at 1:21 am
Alexandre Girard
Do you webserver log show something? You might use some deprecated methods that are displayed in the webserver log used by Rails (webrick, mongrel, apache, …)