Question

I have a simple jquery-(ujs) script that adds some values in different fields on a page. (NO AJAX)

This runs fine in rails 3.2 development mode, however it doesn't run in production mode at all.

application.js file is :

 //= require jquery
 //= require jquery_ujs
 //= require_tree .

(And I have my adder_func.js files in this directory) ..

I have the 'jquery-rails' in the Gemfile -- done bundle update .. I have regenerated the asset pipeline with

 rake assets:clean
 rake assets:precompile

However in the the production mode, editing the fields doesn't update the related fields ..

Same application run in development mode with

  rails s

localhost:3000/pagexxx and javascript works ..

with phusion-passenger -- apache2 localhost:80/pagexxx everything works fine except javacscript.

Stylesheets and images etc. are all being delivered from the single file "application.css" and there is an "applicaton.js" being loaded with my functions in it. there are no errors on the console with javascript. It's an asset pipleline issue .. but I can't see what I am doing wrong.

Was it helpful?

Solution

The problem was bad js library files in javascript directory. I had 4 js libraries in the javascripts directory .. prototype, dragdrop, effects and control.js - i didn't need them but they were there since rails 2.3 days and i never bothered to get rid of them.

I removed them and everything works.

There are two possibilities -- one is that there is a "conflicting" function name in the libraries with jquery .. or there is a missing syntax error; I think it's the latter.

When files are served individually as in the development mode, a bad file doesn't affect anything unless the script gets used. However when sprockets combines them into a single application.js file .. then you could get into this kind of problem.

Assets precompile doesn't give a warning/error-message for such conflicts or issues and that's a bummer.

OTHER TIPS

Check your production.rb in config\environments and check if any configuration for the assets is needed. Depending on your settings you manually need to add the js file here.

Search for the line: # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top