Q:

Properly setting up coffee script with my ruby on rails page

Im looking at the basic guide on how to use javascript in ROR.
I am familiar with javascipt (and jquery) but not really with coffee script. 
The guide is pretty straightforward. Im just missing where i should place my coffee script for it to work.
I am trying to make the 
paintIt = (element, backgroundColor, textColor) ->
  element.style.backgroundColor = backgroundColor
  if textColor?
    element.style.color = textColor

function work. 
I place the 
<a href="#" onclick="paintIt(this, '#990000')">Paint it red</a>

in my divider. And the code in my \assets\javascripts\pages.js.coffee  (although i tried putting basic javascript in the application.js as well) 
and then i run the server and nothing happens when i click on the link. 
I am assuming i need to compile the coffee script and possibly link it to the page yet i have no idea how to do this. The guide says nothing about it and I dont know what to look for to make my script work

I want to set up the coffee script properly so it works in my page (I dont know if making the all the functions global is the way to go but im assuming its not) 
I got the paintIt function to work by making it global with window.paintIt = as suggested in the comments. 
It has the strange effect of only switching the background color for a second and then reverting it back to transparent background. 
I can provide additional content of my files if you guys need more information. 

A:

Add CoffeScript Rails integration gem by appending gem 'coffee-rails' to your Gemfile
Install dependencies by running bundle
Require your script in application.js
//= require pages

Do not use onclick, set the click event handler in the JS code:
paintIt = -> #....

$ ->
  $('a').click -> paintIt(@, '#990000')

