Assets not being served correctly #2715

Closed
FestivalBobcats opened this Issue Aug 28, 2011 · 43 comments
@FestivalBobcats

I'm not sure how it happened, but yesterday after updating RVM and switching to rails 3.1.0.rc6, I get errors such as this:

ActionController::RoutingError (No route matches [GET] "/stylesheets/application.css")

I've tried locking sprockets to older versions (beta.10, beta.12, beta.14), switching to rails stable, rc5, rc4, rc1, and fiddling with assets config to no avail.

I saw that others had dealt with this recently, but I can't seem to figure out how the hell to fix this. Any ideas?

@spastorino
Ruby on Rails member

Can you post an application to show the issue?

@siong1987

It should be under "/assets/application.css".

But, it should have no problem if you are using:

 <%= stylesheet_link_tag 'application' %>
@spastorino
Ruby on Rails member

ahh yes @siong1987 is right, I didn't realize about it :P.
@FestivalBobcats how are you trying to get the application.css file?

@FestivalBobcats

Alright, with rails 3.1.0.rc5 and sprockets 2.0.0.beta.15:

|-app
|---assets
|-----stylesheets
|-------application.css

/*
*= require_tree .
*/

In my layout file, I have:

= stylesheet_link_tag 'application'

This is the log output:

Started GET "/stylesheets/application.css" for 127.0.0.1 at 2011-08-28 11:06:09 -0500

ActionController::RoutingError (No route matches [GET] "/stylesheets/application.css"):
@siong1987

This is a weird bug. Btw, you have to upgrade to rails 3.1.0.rc6.

@guilleiguaran
Ruby on Rails member

@FestivalBobcats you are testing with a new application or do you upgrade from an old rc?

@FestivalBobcats
@siong1987

What @guilleiguaran trying to ask is whether you are upgrading from old rc to the latest rc6? If you are, you have to do:

rake rails:update
@FestivalBobcats

Hmmm... I just checked out an older commit where I was running rails 3.1.0.rc1, scrapped my gemset, and then ran bundle update. Then I ran

rake rails:update

/Users/bhundley/.rvm/gems/ruby-1.9.2-p290@touchablereviews/gems/rake-0.9.2/lib/rake/version.rb:4: warning: already initialized constant MAJOR
/Users/bhundley/.rvm/gems/ruby-1.9.2-p290@touchablereviews/gems/rake-0.9.2/lib/rake/version.rb:5: warning: already initialized constant MINOR
/Users/bhundley/.rvm/gems/ruby-1.9.2-p290@touchablereviews/gems/rake-0.9.2/lib/rake/version.rb:6: warning: already initialized constant BUILD
/Users/bhundley/.rvm/gems/ruby-1.9.2-p290@touchablereviews/gems/rake-0.9.2/lib/rake/version.rb:3: warning: already initialized constant NUMBERS
/Users/bhundley/.rvm/gems/ruby-1.9.2-p290@touchablereviews/gems/rake-0.9.2/lib/rake/version.rb:9: warning: already initialized constant VERSION
/Users/bhundley/.rvm/gems/ruby-1.9.2-p290@touchablereviews/gems/rake-0.9.2/lib/rake.rb:26: warning: already initialized constant RAKEVERSION
/Users/bhundley/.rvm/gems/ruby-1.9.2-p290@touchablereviews/gems/rake-0.9.2/lib/rake/early_time.rb:17: warning: already initialized constant EARLY
/Users/bhundley/.rvm/gems/ruby-1.9.2-p290@touchablereviews/gems/rake-0.9.2/lib/rake/alt_system.rb:32: warning: already initialized constant WINDOWS
/Users/bhundley/.rvm/gems/ruby-1.9.2-p290@touchablereviews/gems/rake-0.9.2/lib/rake/application.rb:28: warning: already initialized constant DEFAULT_RAKEFILES
WARNING: Possible conflict with Rake extension: String#ext already exists
WARNING: Possible conflict with Rake extension: String#pathmap already exists
/Users/bhundley/.rvm/gems/ruby-1.9.2-p290@touchablereviews/gems/rake-0.9.2/lib/rake/task_arguments.rb:73: warning: already initialized constant EMPTY_TASK_ARGS
/Users/bhundley/.rvm/gems/ruby-1.9.2-p290@touchablereviews/gems/rake-0.9.2/lib/rake/invocation_chain.rb:49: warning: already initialized constant EMPTY
/Users/bhundley/.rvm/gems/ruby-1.9.2-p290@touchablereviews/gems/rake-0.9.2/lib/rake/file_utils.rb:10: warning: already initialized constant RUBY
/Users/bhundley/.rvm/gems/ruby-1.9.2-p290@touchablereviews/gems/rake-0.9.2/lib/rake/file_utils.rb:84: warning: already initialized constant LN_SUPPORTED
/Users/bhundley/.rvm/gems/ruby-1.9.2-p290@touchablereviews/gems/rake-0.9.2/lib/rake/dsl_definition.rb:143: warning: already initialized constant Commands
/Users/bhundley/.rvm/gems/ruby-1.9.2-p290@touchablereviews/gems/rake-0.9.2/lib/rake/file_list.rb:44: warning: already initialized constant ARRAY_METHODS
/Users/bhundley/.rvm/gems/ruby-1.9.2-p290@touchablereviews/gems/rake-0.9.2/lib/rake/file_list.rb:47: warning: already initialized constant MUST_DEFINE
/Users/bhundley/.rvm/gems/ruby-1.9.2-p290@touchablereviews/gems/rake-0.9.2/lib/rake/file_list.rb:51: warning: already initialized constant MUST_NOT_DEFINE
/Users/bhundley/.rvm/gems/ruby-1.9.2-p290@touchablereviews/gems/rake-0.9.2/lib/rake/file_list.rb:55: warning: already initialized constant SPECIAL_RETURN
/Users/bhundley/.rvm/gems/ruby-1.9.2-p290@touchablereviews/gems/rake-0.9.2/lib/rake/file_list.rb:61: warning: already initialized constant DELEGATING_METHODS
/Users/bhundley/.rvm/gems/ruby-1.9.2-p290@touchablereviews/gems/rake-0.9.2/lib/rake/file_list.rb:364: warning: already initialized constant DEFAULT_IGNORE_PATTERNS
/Users/bhundley/.rvm/gems/ruby-1.9.2-p290@touchablereviews/gems/rake-0.9.2/lib/rake/file_list.rb:370: warning: already initialized constant DEFAULT_IGNORE_PROCS
/Users/bhundley/.rvm/gems/ruby-1.9.2-p290@touchablereviews/gems/rake-0.9.2/lib/rake.rb:64: warning: already initialized constant FileList
/Users/bhundley/.rvm/gems/ruby-1.9.2-p290@touchablereviews/gems/rake-0.9.2/lib/rake.rb:65: warning: already initialized constant RakeFileUtils
rake aborted!
stack level too deep
@guilleiguaran
Ruby on Rails member

@FestivalBobcats can you post your application.rb ?

@FestivalBobcats
require File.expand_path('../boot', __FILE__)

require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"

Bundler.require(:default, Rails.env) if defined?(Bundler)

module Monocle
  class Application < Rails::Application

    config.autoload_paths += %W(#{config.root}/lib)

    config.encoding = "utf-8"

    config.filter_parameters += [:password]
    config.filter_parameters << :payment

    config.assets.enabled = true
  end
end
@guilleiguaran
Ruby on Rails member

@FestivalBobcats: add one more require to your application.rb and try again:

require "sprockets/railtie"
@FestivalBobcats

Aha! Thanks @guilleiguara!

Works great on rc6 now.

@chicks

I ran into this issue as well when going from rc2 to rc8. Thanks!

@stewartmatheson

I still have this issue on rails 3.1.3 however I have upgraded my applicaiton form 3.0.0. Is there something I am missing in my application.rb file?

require File.expand_path('../boot', __FILE__)

require 'rails/all'
require "sprockets/railtie"

# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
# Bundler.require(:default, Rails.env) if defined?(Bundler)

if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
  Bundler.require *Rails.groups(:assets => %w(development test))
  # If you want your assets lazily compiled in production, use this line
  # Bundler.require(:default, :assets, Rails.env)
end


module MyApp
  class Application < Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Custom directories with classes and modules you want to be autoloadable.
    # config.autoload_paths += %W(#{config.root}/extras)

    # Only load the plugins named here, in the order given (default is alphabetical).
    # :all can be used as a placeholder for all plugins not explicitly named.
    # config.plugins = [ :exception_notification, :ssl_requirement, :all ]

    # Activate observers that should always be running.
    # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
    config.active_record.observers = :shift_notification_observer

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    #config.time_zone = 'Central Time (US & Canada)'


    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    # config.i18n.default_locale = :de

    # JavaScript files you want as :defaults (application.js is always included).
    # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)

    # Configure the default encoding used in templates for Ruby 1.9.
    config.encoding = "utf-8"

    # Configure sensitive parameters which will be filtered from the log file.
    config.filter_parameters += [:password]

    config.time_zone = 'UTC'

    config.generators do |g|
      g.test_framework :rspec
    end


    # Enable the asset pipeline
    config.assets.enabled = true

    # Version of your assets, change this if you want to expire all your assets
    config.assets.version = '1.0'

    # Change the path that assets are served from
    #config.assets.prefix = "/assets"


    config.middleware.use ::ExceptionNotifier,
      :email_prefix => "",
      :sender_address => %w{none@no-where.com},
      :exception_recipients => %w{no-one@no-where.com}

  end
end
@stewartmatheson

If its a bug in the rails code then let me know. I would love to try and submit a patch for this... but i think its a config issue on my end :)

@doubleminus

Same issue here. Rails 3.1.3.

Started GET "/assets/images/img05.jpg" for 127.0.0.1 at 2012-01-01 18:25:41 -0800
Served asset /images/img05.jpg - 404 Not Found (2ms)

Same for all other image files in /assets/images folder. These files definitely all exist in that folder with correct names. The application is very new and barely modified from defaults.

@stewartmatheson

I don't think this is a bug in the code as I rolled a 3.0.0 from scratch and updated to 3.1.3 and there was no issue. In the mean time you can work around this issue by passing the full path to the helper. The manifest file will work as expected.

@chrismccord

I too am experiencing this issue after upgrading to 3.2.0.rc1 coming from 3.1.1. All assets throw a routing error ie.

Started GET "/assets/application.js" for 127.0.0.1 at 2012-01-03 16:31:05 -0500
Served asset /application.js - 404 Not Found (0ms)

require "sprockets/railtie" inclusion in application.rb has no effect.

@cyphactor

@chrismccord, I just upgraded from a Rails 3.1.0 app to Rails 3.2.0 for one of my projects at work and I am having the same problem. The strange thing is that one of my personal projects which was also a Rails 3.1.0 to Rails 3.2.0 seems to be working fine. I am not quite sure what is causing this. Any direction or help in resolving this would be much appreciated.

requiere "sprockets/railtie"

in the application.rb had no effect.

@guilleiguaran
Ruby on Rails member

do you know a way to reproduce your issue in a blank app?

@cyphactor

@guilleiguaran, sadly I have not been able to create an empty app yet that reproduces this issues. It is a tricky bug/miss-configuration. It seems like it is one of those things where when you have the right combinations of things it fails. Just not sure what the right combination is to make it fail.

@chrismccord

@cyphactor the only solution we came up with on our project was to manually specify the asset paths. application.rb:

config.assets.paths << Rails.root.join("app", "assets", "stylesheets")
config.assets.paths << Rails.root.join("app", "assets", "javascripts")
config.assets.paths << Rails.root.join("vendor", "assets", "stylesheets")
config.assets.paths << Rails.root.join("vendor", "assets", "javascripts")

The unusual thing was that Rails.application.assets.paths via rails console would display the correct paths before the above fix was added. @guilleiguaran I cannot replicate this issue with a fresh 3.2 app and have had no success pinpointing what could be causing this.

@cyphactor

@chrismccord, thx for the info. I thought maybe it was some how dealing with some weird caching problems so I nuked my repo and did a fresh clone. That did NOT solve it either. So then I tried specifying the paths explicitly in the application.rb as you suggest and that worked.

I also verified as you said that the paths are correct in rails console when you inspect them so I am not sure how they are getting nuked in some scenarios but not in others. Anyways, thx again for the info at least this will allow me to move forward with rails 3.2.

@gucki

I had the same problems and found it's caused by having active_reload in the Gemfile. Removing the gem active_reload from the Gemfile solved all assets problems for me. And it's not needed with rails 3.2 anyway.

@koops

I also have this issue after upgrading to 3.2. Strangely, images and javascript assets are not affected, only stylesheets. The asset pipeline still works if i change the stylesheet link to what it's supposed to be (with the "assets" prefix).

@jodigiordano

@gucki yep that did it for me too! I removed active_reload and now it's working fine!

@tma

Thanks, @gucki fixed the problem for me too! :)

@koops

I don't have active_reload anywhere in my Gemfile.lock and it's still happening to me.

EDIT: this was caused by the mobile_fu on rubygems.org. Thank you, Method#source_location.

@christoph-buente

I have the same issue after an upgrade of a rails 3.0 app to 3.1.

rake assets:precompile

runs fine and creates a file public/assets/application-68a93fd8bfe810d66963007fb13a6dbc.css

Loading the page says:

No route matches [GET] "/assets/application-68a93fd8bfe810d66963007fb13a6dbc.css"

I'm using rails 3.1.4 with sprockets 2.0.3

@TatianaTyu

@gucki, thank you! My issue was with this active_reload gem, too.

@sudershan15

I have no active_reload in Gemfile and it is the issue.... plz help

@cyphactor

@sudershan15 maybe you have a gem in your Gemfile that has active_reload as a dependency? You can check this by looking for active_reload in your Gemfile.lock as it contains the dependency tree for the gems.

@sudershan15

@cyphactor there is no active_reload in Gemfile.lock too

@cyphactor

@sudershan15 my guess would then be that there is a gem that you are using that integrates itself with Rails in a similar fashion to how active_reload does. I am not sure of what plugins these might be off hand. But, if you provide your Gemfile I would be glad to take a look and see if anything jumps out at me. I am sure that others may have suggestions as well once they see your Gemfile.

@sudershan15

Gemfile.lock:

GEM
remote: https://rubygems.org/
specs:
actionmailer (3.2.3)
actionpack (= 3.2.3)
mail (~> 2.4.4)
actionpack (3.2.3)
activemodel (= 3.2.3)
activesupport (= 3.2.3)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.1)
rack (~> 1.4.0)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.1.2)
activemodel (3.2.3)
activesupport (= 3.2.3)
builder (~> 3.0.0)
activerecord (3.2.3)
activemodel (= 3.2.3)
activesupport (= 3.2.3)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activeresource (3.2.3)
activemodel (= 3.2.3)
activesupport (= 3.2.3)
activesupport (3.2.3)
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
builder (3.0.0)
erubis (2.7.0)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.3)
jquery-rails (2.0.2)
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
json (1.7.0)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.18)
multi_json (1.3.4)
mysql2 (0.3.11-x86-mingw32)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack (>= 1.0)
rails (3.2.3)
actionmailer (= 3.2.3)
actionpack (= 3.2.3)
activerecord (= 3.2.3)
activeresource (= 3.2.3)
activesupport (= 3.2.3)
bundler (~> 1.0)
railties (= 3.2.3)
railties (3.2.3)
actionpack (= 3.2.3)
activesupport (= 3.2.3)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
sprockets (2.1.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.33)

PLATFORMS
x86-mingw32

DEPENDENCIES
jquery-rails
mysql2
rails (= 3.2.3)

Gemfile:

source 'https://rubygems.org'

gem 'rails', '3.2.3'

Bundle edge Rails instead:

gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'mysql2'

Gems used only for assets and not required

in production environments by default.

group :assets do
#gem 'sass-rails', '~> 3.2.3'
#gem 'coffee-rails', '~> 3.2.1'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platform => :ruby

#gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

To use ActiveModel has_secure_password

gem 'bcrypt-ruby', '~> 3.0.0'

To use Jbuilder templates for JSON

gem 'jbuilder'

Use unicorn as the app server

gem 'unicorn'

Deploy with Capistrano

gem 'capistrano'

To use debugger

gem 'ruby-debug19', :require => 'ruby-debug'

@sudershan15

source 'https://rubygems.org'

gem 'rails', '3.2.3'

Bundle edge Rails instead:

gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'mysql2'

Gems used only for assets and not required

in production environments by default.

group :assets do
#gem 'sass-rails', '~> 3.2.3'
#gem 'coffee-rails', '~> 3.2.1'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platform => :ruby

#gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

To use ActiveModel has_secure_password

gem 'bcrypt-ruby', '~> 3.0.0'

To use Jbuilder templates for JSON

gem 'jbuilder'

Use unicorn as the app server

gem 'unicorn'

Deploy with Capistrano

gem 'capistrano'

To use debugger

gem 'ruby-debug19', :require => 'ruby-debug'

@sudershan15

////////m sorry all the things in bold are commented with # in front

@sudershan15

@cyphactor ny solution for this??

@spastorino
Ruby on Rails member

@sedershan15 can you open a new report explaining the issue you're hitting, what version are you using? and If you can sharing an app reproducing it. This issue was probably another one and it's already fixed. Thanks a lot :)

@cyphactor

@sudershan15, sorry don't see anything horribly out of the ordinary. I recommend following @spastorino's directions and putting up a github repo that reproduces the problem.

@gabrielengel

Had the same issue here. I have no idea why nor how, but my production.rb was in the config/initilizers folder instead of config/environments. (Rails 4.2.1)
Make sure assets compilation is not being set to false somewhere in your application. Maybe an initilizer. Maybe force assets compilation:

config.assets.compile = true
@zeltice

@gabrielengel Are you sure that's wise? If we set compile to true for production.rb wouldn't every web request make the app run through the asset pipeline in order to generate the correct URLs?

Sounds problematic, performance-wise -- unless Rails uses a hidden internal cache somewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment