Rails 3.1 Asset Pipeline Javascript - specifying page load though jQuery -> -
this causing me lot of frustration. i'm hoping can me out.
in application.js file have following:
//= require jquery //= require jquery_ujs //= require jquery.remotipart //= require jquery-ui //= require jquery.purr //= require jquery.slides //= require best_in_place //= require twitter/bootstrap //= require_tree .
do need have following (or equivalent) in 1 or of page specific javascripts? know in production merged 1 file asset pipeline so... lead off 1 file, no files, files this...?
jquery ->
what i've found adding "jquery ->" or "$ ->" top of resource-specific javascripts works. problem have 1 resource nothing works unless remove "jquery ->". since resource's js file interacts resource's js file functions, etc. have remove "jquery ->" , causing unintended behavior.
just wondering best practice js files in asset pipeline , getting them work one.
thanks
you can't rely on order of assets being loaded when using require_tree
. if going use javascript files dependent on eachother, make sure require them in correct order.
so instead of:
//= require_tree .
use
//= require posts //= require comments
and call functions or whatever defined in posts in comments javascript file.
furthermore, when using coffeescript assume do, have use namespace in order variables avaible throughout application.
so example.
posts.js.coffee
$ -> window.my_super_variable = 'super' window.my_super_function = (message) -> alert(message)
comments.js.coffee
$ -> my_super_variable += ' awesome' my_super_function(my_super_variable)
if don't use window
when defining variables or functions won't accessible globally.
Comments
Post a Comment