javascript - Why my coffeescript function is not executed? -


i new i'm trying follow http://guides.rubyonrails.org/working_with_javascript_in_rails.html , http://guides.rubyonrails.org/asset_pipeline.html rails guides (i'm using rails 4)

so in views/mycontroller have

<a href="#" onclick="paintit(this, '#990000')">paint red</a> 

in app/assets/javascripts/mycontroller.js.coffee paintit function

paintit = (element, backgroundcolor, textcolor) ->   element.style.backgroundcolor = backgroundcolor   if textcolor?    element.style.color = textcolor 

in app/assets/javascripts/application.js have directive:

//= require_tree . 

so coffeescript in mycontroller.js.coffee should compiled

and in views/layouts/application have the

javascript_include_tag "application" 

i checked coffee-rails gem in gemfile , installed.

however in view see "paint red" link coffeescript function not triggered. (nothing happens)

also checked if write javascript inline work

why this? missing?

as stated in comments, coffee-script uses top-level function wrapper. if compile file manually can use --bare command line option.

else point following post: how can use option "--bare" in rails 3.1 coffeescript?


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -