7

I try to upgrade my application from rails 3.1.3 to rails 3.2.1 and I have a problem with assets.

I have this kind of error :

ActionController::RoutingError (No route matches [GET] "/assets/logos/opera_logo.png"):
  actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.1) lib/rails/rack/logger.rb:26:in `call_app'
  railties (3.2.1) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.1) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.1) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/static.rb:53:in `call'
  railties (3.2.1) lib/rails/engine.rb:479:in `call'
  railties (3.2.1) lib/rails/application.rb:220:in `call'
  rack (1.4.1) lib/rack/content_length.rb:14:in `call'
  railties (3.2.1) lib/rails/rack/log_tailer.rb:14:in `call'
  rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
  /usr/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
  /usr/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
  /usr/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'

Rails don't find all my assets but I think than they are in the right folder (app/assets/images/logos/ for example).

I followed this guide for upgrade my system : http://railscasts.com/episodes/318-upgrading-to-rails-3-2?view=asciicast. It was running very well with rails 3.1. I don't find any other change to do. What can I do?

This is my Gemfile :

source 'http://rubygems.org'

gem 'rails', '3.2.1'

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

gem 'sqlite3'


# 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'
  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
  gem 'capybara', '1.1.2'
  gem 'rspec-rails', '2.8.1'
  gem 'autotest-rails', '4.1.1'
  gem 'spork', '0.8.5'
  gem 'factory_girl_rails', '1.4.0'
  gem 'email_spec', '1.2.1'
  gem 'cucumber-rails', '1.2.1'
  gem 'launchy', '2.0.5'
  gem 'pickle', '0.4.10'
  gem 'database_cleaner', '0.7.0'
  gem 'simplecov', '0.5.4'
  gem 'simplecov-rcov', '0.2.3'
  gem "mocha", '0.10.0'
  gem 'capybara-firebug', '0.0.10'
  gem "prawn", '0.8.4'
end

group :development do
  gem "nifty-generators", '0.4.6'
end

gem 'active_reload', '0.6.1'
gem "galetahub-simple_captcha", '0.1.3', :require => "simple_captcha"
gem 'authlogic', '3.1.0'
gem 'meta_search', '1.1.3'
gem 'naive_bayes', :git => 'git://github.com/reddavis/Naive-Bayes.git'

This is my development.rb :

Onopia::Application.configure do
  # Settings specified here will take precedence over those in config/application.rb

  # In the development environment your application's code is reloaded on
  # every request.  This slows down response time but is perfect for development
  # since you don't have to restart the web server when you make code changes.
  config.cache_classes = false

  # Log error messages when you accidentally call methods on nil.
  config.whiny_nils = true

  # Show full error reports and disable caching
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  # Don't care if the mailer can't send
  config.action_mailer.raise_delivery_errors = false

  # Print deprecation notices to the Rails logger
  config.active_support.deprecation = :log

  # Only use best-standards-support built into browsers
  config.action_dispatch.best_standards_support = :builtin

  # Do not compress assets
  config.assets.compress = false

  # Expands the lines which load the assets
  config.assets.debug = true

  # Raise exception on mass assignment protection for Active Record models
  config.active_record.mass_assignment_sanitizer = :strict

  # Log the query plan for queries taking more than this (works
  # with SQLite, MySQL, and PostgreSQL)
  config.active_record.auto_explain_threshold_in_seconds = 0.5
end

And this is my application.rb :

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

# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"

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 Onopia
  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

    # 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 = :fr

    # 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]

    # 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'

    # Configure generators values. Many other options are available,
    # be sure to check the documentation.
    #config.generators do |g|
    #  g.test_framework :rspec, :fixture => false
    #end

    config.action_mailer.default_url_options = { :host => 'localhost:3000' }
  end
end

Edit: a better example.

I want to view this file :

app/assets/javascripts/application.js

When I go to this url :

http://localhost:3000/assets/application.js

And I have this error :

Started GET "/assets/application.js" for 127.0.0.1 at 2012-02-06 17:04:38 -0500
Served asset /application.js - 404 Not Found (1ms)

ActionController::RoutingError (No route matches [GET] "/assets/application.js"):
  actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.1) lib/rails/rack/logger.rb:26:in `call_app'
  railties (3.2.1) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.1) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.1) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/static.rb:53:in `call'
  railties (3.2.1) lib/rails/engine.rb:479:in `call'
  railties (3.2.1) lib/rails/application.rb:220:in `call'
  rack (1.4.1) lib/rack/content_length.rb:14:in `call'
  railties (3.2.1) lib/rails/rack/log_tailer.rb:14:in `call'
  rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
  /usr/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
  /usr/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
  /usr/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'

Thanks a lot and have a nice day.

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
Dougui
  • 7,142
  • 7
  • 52
  • 87
  • You say the asset is in `app/assets/images`, but you are calling the image from the `app/assets/logos` – Alexei Danchenkov Feb 05 '12 at 19:01
  • Sorry, it's my mistake. My file is here : app/assets/images/logos/opera_logo.png. I edited my post. – Dougui Feb 05 '12 at 19:50
  • I wonder if editing a post changed the RoutingError message. According to your log above the image you refer to is not in the `assets/images` folder, but in `assets/logos`. Change the location of your file to `assets/logos` or better find the referring link and change it to match `assets/images/opera_logo.png` – Alexei Danchenkov Feb 05 '12 at 20:08
  • If the above will not help, check the assets generation by trying, for example `http://localhost:3000/assets/application.css`. You shall see if your styles were generated under `assets` folder. If they weren't, check if assets pipeline is at all enabled. – Alexei Danchenkov Feb 05 '12 at 20:20
  • Sorry, I choosed the wrong example. This is the same with application.css which is locate at this place app/assets/stylesheets/application.css. I have this error : ActionController::RoutingError (No route matches [GET] "/assets/application.css") – Dougui Feb 05 '12 at 20:35
  • Would you show the contents of your Gemfile and your development.rb file (assuming you run your code in dev mode)? – Alexei Danchenkov Feb 06 '12 at 03:50
  • I edit my post to add Gemfile, development.rb and application.rb – Dougui Feb 06 '12 at 11:55
  • I edit my post to put a better example. – Dougui Feb 06 '12 at 22:09

5 Answers5

13

I hit a similar problem that I resolved by removing the active_reload gem.

Matt Green
  • 2,032
  • 2
  • 22
  • 36
2

Apparently some gem dependency is broken and bundle exec rails server should resolve this. This should be run without sudo ... unless you usually work with your app with root privileges (which is not good). Check the files/folders permissions in your rails root, which might have been broken by misusing sudo commands earlier. While in development you hardly need any root privileges.

Other than that, similar issues have also appeared before and the answer was to update your entire gemset, primarily sprockets and rails. Your configuration files look okay to me and I can't reproduce the error.

If that does not help, I would create a new rails app, check the assets pipeline working there with the same gemset that you have and manually cross-check all config files.

There are various debugging tools for routing too, but try the above first.

Community
  • 1
  • 1
Alexei Danchenkov
  • 2,011
  • 5
  • 34
  • 49
  • I installed a new gemset, with RVM, and it works! Thanks a lot. – Dougui Feb 08 '12 at 01:08
  • I started rails server with `bundle exec rails s` and it works. The strage thing about this error is that other assets (javascripts, stylesheets) work fine with `rails s` but images don't. – Giovanni Cappellotto Feb 24 '12 at 14:27
  • @Giovanni You are giving too few details to understand. Please, start a new question explaining your situation. Make sure to include your `Gemfile` and calls to images assets that do not work and full error messages. – Alexei Danchenkov Feb 24 '12 at 15:06
0

New to Rails, but for my images located in the directory ../app/assets/images e.g. "rails.png" the proper CSS reference for a background image is: background: white url(rails.png) repeat-y; (options shown)

Even though it is in the images folder, with rails 3.2.6 (version I'm using), you don't put the images part of the directory.

Jay H.
  • 843
  • 7
  • 6
0

I encountered something similar earlier. How are you referencing them? Is it an image_tag failing or CSS reference failing?

If your file is here /app/assets/images/logos/opera_logo.png then the following references should work.

From an html.erb file: <%= image_tag('logos/opera_logo.png') %>

From an scss file: background: url(image_path("logos/opera_logo.png"))

http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets

manafire
  • 5,984
  • 4
  • 43
  • 53
0

Try adding this to your Gemfile and restart the server, as per: http://guides.rubyonrails.org/asset_pipeline.html#upgrading-from-old-versions-of-rails

# 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"
  gem 'uglifier'
end
manafire
  • 5,984
  • 4
  • 43
  • 53