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 réflexions au sujet de « Using RJS templates »
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.
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, …)