Bharat Ruparel
2012-Apr-01 21:31 UTC
asset pipeline/coffeescript triggering event twice instead of once
This does not make any sense to me: I have a model called TypeWell along with it controller and forms. If I attach a jQuery event Handler using old fashioned Javascript code to its form partial like shown below: :javascript $(document).ready(function() { $("#type_well_gas_type").change(function() { alert("Gas type changed"); }); }); It alerts the message once (correctly) as shown when I change the gas_type drop-down. If however, I move this code from the form partial (app/views/type_wells/_form.haml.html to the corresponding coffeescript file app/assets/javascripts/type_wells.js.coffee (of course delete it from the form partical) as shown below: $(document).ready -> $("#type_well_gas_type").change -> alert "gas type changed" then it triggers twice instead of once as expected? This is as basic as it gets. Is there something that I do not understand about asset pipeline that is causing this behavior? Please explain. Thanks. Bharat -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Bharat Ruparel
2012-Apr-01 22:20 UTC
Re: asset pipeline/coffeescript triggering event twice instead of once
OK. I have figure this out and am posting the solution here so that someone who runs into this problem can benefit from this knowledge. At some point in time, I have pre-compiled the coffeescript files to javascript in my assets/javascripts folder and therefore there were corresponding javascript files along with the coffeescript files in my development environment. Asset pipeline was executing both instead of either! So the moral of the exercise is that if you are using coffeescript, be sure to delete corresponding javascript files from the assets/javascripts folder. As soon as I deleted app/assets/javascripts/type_wells.js.js file, everything worked as expected Bharat -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.