Bryan Ashley

Web Developer

Page specific, Dom-Ready Javascript Execution in Rails

An extension of an extension of Paul Irish’s Dom-Ready Execution

Page specific bindings in rails can be achieved in many different ways. Recently I came across this post by @brandonhilkert and it inspired me to post about the solution that I have been using for awhile.

Now it is important to note that I did not come up with what I currently use on my own. It all started with a solution that @paul_irish had posted in 2009 here and then was extended to be even more awesome by @jgarber here. With all of the creds handed out appropriately, I’ll show how a colleague @mtrpcic and I were able to extend @jgarber’s solution even further.

So alike @jgarber and @paul_irish’s solution the first thing required is to use the rails controller_name and action_name helper as data attributes on the body.

<body data-controller=“<%= controller_name %>” data-action=“<%= action_name %>” >

With that...

Continue reading →