Question

I'm not sure why, but whenever I run rake assets:precompile, application.js doesn't get compiled. I get a "application.js isn't precompiled" error in production mode.

Here is my Gemfile if it means anything:

source 'http://rubygems.org'

gem 'rails', '3.1.1'
gem 'eventmachine', '1.0.0.beta.4.1'
gem 'thin'
gem 'mysql'
gem 'win32-open3-19'
gem 'paperclip', '2.3.8'
#gem 'jammit'
gem 'jsmin'
gem 'will_paginate'

# Bundle edge Rails instead:
# gem 'rails',     :git => 'git://github.com/rails/rails.git'


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.1.4'
  gem 'coffee-rails', '~> 3.1.1'
  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'

group :test do
  # Pretty printed test output
  gem 'turn', :require => false
end

I made a new rails app and tested the rake assets:precompile and it's working. The only difference between the two apps in terms of relevant files would be what gems I have installed. "application.js" is the same between both apps...as are the environment.rb files.

Also of note...when I include a random .js file in my assets/javascripts directory and use "javascript_include_tag :application", one of the resulting URLs in dev mode look like so: /assets/../javascripts/anytimec.js?body=1 and they obviously fail with 404. However the application.js file is referenced correctly.

UPDATE:

Looking into what Sprockets generates I've noticed that the "logical path" uses "../javascripts" in the location. I tested this by looking at the dump of asset_paths.asset_for('application','js') and asset_paths.asset_for('anytimec','js') respectively. I've also compared those dumps to the same files from a fresh application. The fresh application does NOT prepend the "../javascripts" to the location whereas my current app DOES. It doesn't do this to the CSS files or anything else...just javascript. This is most definitely alluding to the core problem but I don't know where to go from here.

Was it helpful?

Solution

After discovering that it had to do with Sprockets failing when reading a folder specifically called "java" in the assets folder, I renamed it to "applets" and it started working.

See this post for the answer.

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