ruby on rails 3 - Why are my coffeescript functions not available from my HTML code ? -


i using rails-backbone, coffeescript gems in rails 3.2.6 project.

square = (x) -> x * x alert square(5)

this blog.js.coffee script file produces:

(function() { var square; square = function(x) {return x * x;}; alert(square(5));

i need call square() method in other view file.

how can call that? there thing wrong doing?

all code in coffeescript inside self-invoking anonymous function.

to call outside file, write:

window.square = (x) -> x * x  

alert(square(5)) in other function

the best can not overuse window app object contain variables.

window.app={} window.app.square=  (x) -> x * x  

and alert(app.square(5))


Comments