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'