Storing .js files and .css files in ‘js’ and ‘css’ directories in Rails 2.2

In the years I have been working with Rails I have generally been happy to follow the conventions that it enforces. There is one that just doesn’t sit right with me and that is the decision to store .css files in a ‘stylesheets’ directory and .js files in a ‘javascripts’ directory as I prefer ‘css’ and ‘js’ directories (call me old fashioned).

Achieving this in Rails 2.2 involves changing a couple of constants. I may submit a patch with a config hook for this as it feels a little dirty changing the constants directly. Add the following lines to your environment.rb file.


ActionView::Helpers::AssetTagHelper::StylesheetAsset::DIRECTORY = 'css'.freeze
ActionView::Helpers::AssetTagHelper::JavaScriptAsset::DIRECTORY = 'js'.freeze

Published by

Jamie

Hi, I am the Managing Director of SonicIQ Limited in the UK. I have been working in the web development industry since 1999 and have been running SonicIQ since 2001. Currently Ruby On Rails is my preferred development platform. I am experienced in designing with web standards, HTML5, CSS3 and Javascript.

3 thoughts on “Storing .js files and .css files in ‘js’ and ‘css’ directories in Rails 2.2”

  1. Nice idea, I had to do something like this once to replace a legacy system with a bunch of external dependencies on its stylesheets.

    What about images?

  2. Hi Ed,

    For images you could redefine as follows:

    ActionView::Helpers::AssetTagHelper::ImageAsset::DIRECTORY = 'custom_images'.freeze
    

    Jamie

  3. This really goes against the convention over configuration ideology of rails (which you already know), and imo – isn’t one worth toying with. May as well start playing with the naming conventions, because someone simply doesn’t like what it’s called. I’m in agreeance with you – I think css/js are much better directory names, but changing the application to match my own taste in naming is a waste of time.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>