in my app I have one controller supporting a quite complex object that has a lot of javascript, written in coffescript.
I would like to arrange the javascript on several separate files so to have the code arranged more nicely, although I can't figure out how to import these extra files.
for example I have the file app/assets/javascripts/general_functions.js.coffee
containing the following:
# rounds a number roundNumber = (rnum, rlength = 5) -> pow = Math.pow( 10, rlength ) newnumber = Math.round(rnum*pow)/pow parseFloat(newnumber) # floors a number floorNumber = (rnum, rlength = 5) -> pow = Math.pow( 10, rlength ) newnumber = Math.floor(rnum*pow)/pow parseFloat(newnumber) # returns true if the str ends with suffix endsWith = (str, suffix) -> str.indexOf(suffix, str.length - suffix.length) != -1 # returns the absolute value of a number (always >= 0) abs = (num) -> if num < 0 then - num else num
How do I import it in my app/assets/javascripts/projects.js.coffee
that needs these functions?
I've tried with adding
//= require general_functions
to app/assets/javascripts/application.js
, with no success
any ideas?
thanks,