0

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.

4
  • I am unclear what works in production. Does regular javascript work in production? What do you see in the application.js in production? Commented Mar 2, 2014 at 6:42
  • I don't have any other javascript functions -- delivery of css and images etc. compiled by rake asset:precompile seems to be fine .. as I said the preocomipled application.js does have my code compiled in it. Commented Mar 2, 2014 at 6:48
  • Wait, so you don't have any other javascript functions, but then you can see your code compiled in the application.js? Commented Mar 2, 2014 at 6:49
  • YES .. I said I have my one file with adder.js file in the app/java.../ directory .. it work in development mode and if you compile it .. you can see it in the application.js that's served Commented Mar 2, 2014 at 6:55

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Good explanation! In addition, using the console in Chrome or Firefox can help to recognize some js errors and solve them.
0

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)

1 Comment

Tim, As I said my functions are in a file that's included in the compiled application.js that's served by rails. I can see the code in it. It appears to me that jquery.js and jquery-ujs.js is not being added - in development mode rails pulls it out from somewhere but in production mode (compiled assets) it's missing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.