Category Archives: Rails

Rails page specific JavaScript and CSS

In a Rails project that I was working on, I wanted to come up with a way to separate the JavaScript and CSS code  to be page specific.    I could do this in JavaScript with some namespace techniques such as discussed in the article Javascript Namespace Declaration   CSS appears to pose more of a problem and I was not able to find a good namespace solution other than to use prefixes.

Using Helper Methods

I finally stumbled upon a nice technique using helper methods as described in the selected answer to the post Rails 3.1 asset pipeline: how to load controller-specific scripts?

The following addresses the problem with JavaScript  – I’ll show how this can be extended to CSS later.

Continue reading

Advertisements