Coffeescript Link

I follow the first steps of the guide rails http://edgeguides.rubyonrails.org/working_with_javascript_in_rails.html#unobtrusive-javascript

index.html.erb looks like <a href="#" onclick="paintIt(this, '#990000')">Paint it red</a> <a href="#" onclick="paintIt(this, '#009900', '#FFFFFF')">Paint it green</a> <a href="#" onclick="paintIt(this, '#000099', '#FFFFFF')">Paint it blue</a>

I added coffeescript to app / assets / javascripts / welcome.js.coffee paintIt = (element, backgroundColor, textColor) -> element.style.backgroundColor = backgroundColor if textColor? element.style.color = textColor

I get this error:
Uncaught ReferenceError: paintIt is not defined

I tried switching paintItto @paintItand to window.paintItno avail. I have a temporary fix just using plain old javascript in app / assets / javascripts / applications.js, but I wanted to start using coffeescript. Any suggestions?

+4
source share
1 answer

paintIt . . , , : fooobar.com/questions/137764/...

@vee. , .

+1

Source: https://habr.com/ru/post/1568256/


All Articles