I am very new to this so I'm trying to follow the http://guides.rubyonrails.org/working_with_javascript_in_rails.html and the http://guides.rubyonrails.org/asset_pipeline.html Rails Guides (I'm using Rails 4)
So in views/myController I have
<a href="#" onclick="paintIt(this, '#990000')">Paint it red</a>
In app/assets/javascripts/myController.js.coffee the paintIt function
paintIt = (element, backgroundColor, textColor) ->
element.style.backgroundColor = backgroundColor
if textColor?
element.style.color = textColor
In app/assets/javascripts/application.js I have the directive:
//= require_tree .
so the coffeescript in myController.js.coffee should be compiled
And in views/layouts/application I have the
javascript_include_tag "application"
I also checked that the coffee-rails gem is in the gemfile and installed.
However in my view I see the "Paint it red" link but the coffeescript function is not triggered. (nothing happens)
Also checked that if I write the javascript inline it does work
WHy is this? What am I missing?