Question

I've built a small site as a learning exercise and to give RoRs a go. I was pleased with the results in "dev" running against WEBrick but am having problems moving the site to "production" served via apache (so I can leave it around to look back on).

I've tried a number of small tweaks I've found but nothing seems to correct the problem - after I compile my assets JavaScript stops working - both my custom little jQuery and the built in bootstrap (drop downs) no longer works. The basic HTML is rendered correctly. I do appear to get one error in "application.js" visible in Chrome Developer tools. I feel this might be the problem but I haven't delved deep enough into the "asset pipeline" to catch it.

Can anyone spot where I might be going wrong?

Here are some details and happy to provide more if required. Would love to get this nailed down.

results of running a precompile:

$ bundle exec rake assets:precompile RAILS_ENV=production
Ignoring `ruby` directive. This is a feature added to Bundler 1.2.0 and higher. Please upgrade if you would like to use it.

/usr/bin/ruby1.9.1 /usr/local/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
$

Gemfile:

source 'https://rubygems.org'
ruby '1.9.1'
gem 'rails', '3.2.8'
gem 'mysql2'
gem 'json'
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'therubyracer', :platforms => :ruby
  gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'bootstrap-sass', '~> 2.2.2.0'
gem 'simple_form'
gem 'bcrypt-ruby', '~> 3.0.0'

app/assets/javascripts/application.js:

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

app/assets/javascripts/rootEffects.js (some of my random jQuery):

$(document).ready(function(){
  //Tooltips for gifts
  $('.edit').tooltip({'placement':'top'});
  $('.delete').tooltip({'placement':'top'});
  $('.tip-info').tooltip({'placement':'top'});
  $('.link-buy').tooltip({'placement':'bottom'});
  $('.long-name').tooltip({'placement':'top'});
});

Was going to provide the contents of public/assets/ but not sure if this would help.

Here are the errors I'm seeing via Chrome Dev tools. I'm disregarding the second error on the console as this is Chrome related.

console error

Below is the error shown if I click through from the console. I strongly feel this is related.

JavaScript error

From what I've read and understand - the precompile process is supposed to place all my JavaScript in a single file 'application.js' - possibly the error being thrown is stopping any of it being executed. So far, I haven't found a tweak to correct this so I'm reaching out for help.

Was it helpful?

Solution

Awkward.

I must have played with my application.js in a different dir by accident.

I shifted around the entries again and voila it works (similar to this quesiton JQuery Working in Development, Not Production on Heroku Cedar)

Final application.js:

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

OTHER TIPS

if your JavaScript not work than add following line to production.rb file

config.assets.compile = ['*.js', '*.css']
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top