ruby - How do I import JavaScript files in Rails 3? -


i've started working ruby on rails, , i'm having difficulty calling javascript functions html. i'm using rails 3.2.13, ruby 1.9.3, , rubymine 5.0.2.

i have coffeescript file called "home.js.coffee" in "app/assets/javascripts/" apparently compiles "application.js" in same folder. in "app/views/home/", have html file home page "index.html.erb". have function in "home.js.coffee" called cubes():

cubes = alert math.cube 3 

this basic now. want comfortable first.

this object called math:

math =     cube: (x) -> x* square x 

i created button in index.html.erb should theoretically call function:

<button onclick="cubes()">try it</button> 

the problem getting find javascript file. needs in index.html's head? needs in application.html's head?

the problem function in scope. if compile coffeescript -b option, make functions globally available, simple solution be:

root = exports ? root.cubes = -> alert math.cube 3 

and can call cubes() html.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -