Sharing the Code

Programming stuff that might be useful to others

CoffeeScript setup in Rails

I’ve just started using CoffeeScript with JQuery and Rails and I needed some system to organize my code. I’ve put all my classes and global variables in an app namespace, lets call it MyApp and for each controller I have a class and within that I have static methods for each action that is only run when that action is run.

The first thing I’ve done is put the controler and action in the body tag as data attributes:

[sourcecode language=”html”]
” data-controller=”<%= params[:controller] %>” data-action=”<%= params[:action] %>“>

So if the controller was some_controller and the action was index, it would generate a class name some_controller-index.

Comments are closed