Search code examples
ruby-on-rails-4asset-pipelinegmaps4rails

Rails server : no route matches a javascript asset


I am using Ruby 2 and Rails 4 for my application. I've installed gmaps4rails gem, and moved its assets from lib/assets to vendor/assets (both stylesheets and javascripts directories). The controller that uses gmaps4rails is called FieldsController. Following is my code:

# app/assets/javascripts/fields.js.coffee
//= require gmaps4rails/gmaps4rails.base
//= require gmaps4rails/gmaps4rails.googlemaps

gmaps4rails is a directory in vendor/assets/javascripts.

# config/application.rb
config.assets.precompile += %w[ gmaps4rails.css gmaps4rails/*.js ]

gmaps4rails.css is a file in vendor/assets/stylesheets.

# app/views/layouts/application.html.erb
<head>
...
  <%= stylesheet_link_tag "gmaps4rails" %>
...
</head>

When I launch rails server and move to Fields index page, I have the following log:

Started GET "/fr/fields" for 127.0.0.1 at 2013-09-29 07:08:45 +0200
Started GET "/fr/fields" for 127.0.0.1 at 2013-09-29 07:08:45 +0200
Started GET "/assets/bootstrap-datepicker.css?body=1" for 127.0.0.1 at 2013-09-29 07:08:46 +0200
Started GET "/assets/bootstrap-datepicker.css?body=1" for 127.0.0.1 at 2013-09-29 07:08:46 +0200
Started GET "/assets/comments.css?body=1" for 127.0.0.1 at 2013-09-29 07:08:46 +0200
Started GET "/assets/comments.css?body=1" for 127.0.0.1 at 2013-09-29 07:08:46 +0200
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2013-09-29 07:08:46 +0200
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2013-09-29 07:08:46 +0200
Started GET "/assets/contact.css?body=1" for 127.0.0.1 at 2013-09-29 07:08:46 +0200
Started GET "/assets/contact.css?body=1" for 127.0.0.1 at 2013-09-29 07:08:46 +0200
Started GET "/assets/custom.css?body=1" for 127.0.0.1 at 2013-09-29 07:08:46 +0200
Started GET "/assets/custom.css?body=1" for 127.0.0.1 at 2013-09-29 07:08:46 +0200
Started GET "/assets/fields.css?body=1" for 127.0.0.1 at 2013-09-29 07:08:46 +0200
Started GET "/assets/fields.css?body=1" for 127.0.0.1 at 2013-09-29 07:08:46 +0200
Started GET "/assets/home.css?body=1" for 127.0.0.1 at 2013-09-29 07:08:46 +0200
Started GET "/assets/home.css?body=1" for 127.0.0.1 at 2013-09-29 07:08:46 +0200
Started GET "/assets/matches.css?body=1" for 127.0.0.1 at 2013-09-29 07:08:46 +0200
Started GET "/assets/matches.css?body=1" for 127.0.0.1 at 2013-09-29 07:08:46 +0200
Started GET "/assets/scaffolds.css?body=1" for 127.0.0.1 at 2013-09-29 07:08:46 +0200
Started GET "/assets/scaffolds.css?body=1" for 127.0.0.1 at 2013-09-29 07:08:46 +0200
Started GET "/assets/users.css?body=1" for 127.0.0.1 at 2013-09-29 07:08:46 +0200
Started GET "/assets/users.css?body=1" for 127.0.0.1 at 2013-09-29 07:08:46 +0200
Started GET "/assets/gmaps4rails.css?body=1" for 127.0.0.1 at 2013-09-29 07:08:46 +0200
Started GET "/assets/gmaps4rails.css?body=1" for 127.0.0.1 at 2013-09-29 07:08:46 +0200
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:46 +0200
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:46 +0200
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/turbolinks.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/turbolinks.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-transition.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-transition.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-affix.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-affix.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-alert.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-alert.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-button.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-button.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-carousel.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-carousel.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-collapse.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-collapse.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-dropdown.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-dropdown.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-modal.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-modal.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-scrollspy.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-scrollspy.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-tab.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-tab.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-tooltip.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-tooltip.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-popover.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-popover.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-typeahead.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-typeahead.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/comments.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/comments.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/contact.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/contact.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/gmaps4rails/gmaps4rails.base.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/gmaps4rails/gmaps4rails.base.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/gmaps4rails/gmaps4rails.googlemaps.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/gmaps4rails/gmaps4rails.googlemaps.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/fields.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/fields.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/home.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/home.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-datepicker/core.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-datepicker/core.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-datepicker/locales/bootstrap-datepicker.fr.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/bootstrap-datepicker/locales/bootstrap-datepicker.fr.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/matches.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/matches.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/users.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/users.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/javascripts/gmaps4rails/gmaps4rails.base.js" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/javascripts/gmaps4rails/gmaps4rails.base.js" for 127.0.0.1 at 2013-09-29 07:08:47 +0200

ActionController::RoutingError (No route matches [GET] "/javascripts/gmaps4rails/gmaps4rails.base.js"):
  actionpack (4.0.0.beta1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.0.0.beta1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.0.0.beta1) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.0.0.beta1) lib/rails/rack/logger.rb:21:in `block in call'
  activesupport (4.0.0.beta1) lib/active_support/tagged_logging.rb:67:in `block in tagged'
  activesupport (4.0.0.beta1) lib/active_support/tagged_logging.rb:25:in `tagged'
  activesupport (4.0.0.beta1) lib/active_support/tagged_logging.rb:67:in `tagged'
  railties (4.0.0.beta1) lib/rails/rack/logger.rb:21:in `call'
  actionpack (4.0.0.beta1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.0.0.beta1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  actionpack (4.0.0.beta1) lib/action_dispatch/middleware/static.rb:64:in `call'
  railties (4.0.0.beta1) lib/rails/engine.rb:510:in `call'
  railties (4.0.0.beta1) lib/rails/application.rb:96:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
  /usr/local/rvm/rubies/ruby-2.0.0-rc2/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
  /usr/local/rvm/rubies/ruby-2.0.0-rc2/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
  /usr/local/rvm/rubies/ruby-2.0.0-rc2/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'



ActionController::RoutingError (No route matches [GET] "/javascripts/gmaps4rails/gmaps4rails.base.js"):
  actionpack (4.0.0.beta1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.0.0.beta1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.0.0.beta1) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.0.0.beta1) lib/rails/rack/logger.rb:21:in `block in call'
  activesupport (4.0.0.beta1) lib/active_support/tagged_logging.rb:67:in `block in tagged'
  activesupport (4.0.0.beta1) lib/active_support/tagged_logging.rb:25:in `tagged'
  activesupport (4.0.0.beta1) lib/active_support/tagged_logging.rb:67:in `tagged'
  railties (4.0.0.beta1) lib/rails/rack/logger.rb:21:in `call'
  actionpack (4.0.0.beta1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.0.0.beta1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  actionpack (4.0.0.beta1) lib/action_dispatch/middleware/static.rb:64:in `call'
  railties (4.0.0.beta1) lib/rails/engine.rb:510:in `call'
  railties (4.0.0.beta1) lib/rails/application.rb:96:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
  /usr/local/rvm/rubies/ruby-2.0.0-rc2/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
  /usr/local/rvm/rubies/ruby-2.0.0-rc2/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
  /usr/local/rvm/rubies/ruby-2.0.0-rc2/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'


Started GET "/javascripts/gmaps4rails/gmaps4rails.googlemaps.js" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/javascripts/gmaps4rails/gmaps4rails.googlemaps.js" for 127.0.0.1 at 2013-09-29 07:08:47 +0200

ActionController::RoutingError (No route matches [GET] "/javascripts/gmaps4rails/gmaps4rails.googlemaps.js"):
  actionpack (4.0.0.beta1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.0.0.beta1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.0.0.beta1) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.0.0.beta1) lib/rails/rack/logger.rb:21:in `block in call'
  activesupport (4.0.0.beta1) lib/active_support/tagged_logging.rb:67:in `block in tagged'
  activesupport (4.0.0.beta1) lib/active_support/tagged_logging.rb:25:in `tagged'
  activesupport (4.0.0.beta1) lib/active_support/tagged_logging.rb:67:in `tagged'
  railties (4.0.0.beta1) lib/rails/rack/logger.rb:21:in `call'
  actionpack (4.0.0.beta1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.0.0.beta1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  actionpack (4.0.0.beta1) lib/action_dispatch/middleware/static.rb:64:in `call'
  railties (4.0.0.beta1) lib/rails/engine.rb:510:in `call'
  railties (4.0.0.beta1) lib/rails/application.rb:96:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
  /usr/local/rvm/rubies/ruby-2.0.0-rc2/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
  /usr/local/rvm/rubies/ruby-2.0.0-rc2/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
  /usr/local/rvm/rubies/ruby-2.0.0-rc2/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'



ActionController::RoutingError (No route matches [GET] "/javascripts/gmaps4rails/gmaps4rails.googlemaps.js"):
  actionpack (4.0.0.beta1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.0.0.beta1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.0.0.beta1) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.0.0.beta1) lib/rails/rack/logger.rb:21:in `block in call'
  activesupport (4.0.0.beta1) lib/active_support/tagged_logging.rb:67:in `block in tagged'
  activesupport (4.0.0.beta1) lib/active_support/tagged_logging.rb:25:in `tagged'
  activesupport (4.0.0.beta1) lib/active_support/tagged_logging.rb:67:in `tagged'
  railties (4.0.0.beta1) lib/rails/rack/logger.rb:21:in `call'
  actionpack (4.0.0.beta1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.0.0.beta1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  actionpack (4.0.0.beta1) lib/action_dispatch/middleware/static.rb:64:in `call'
  railties (4.0.0.beta1) lib/rails/engine.rb:510:in `call'
  railties (4.0.0.beta1) lib/rails/application.rb:96:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
  /usr/local/rvm/rubies/ruby-2.0.0-rc2/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
  /usr/local/rvm/rubies/ruby-2.0.0-rc2/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
  /usr/local/rvm/rubies/ruby-2.0.0-rc2/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'

As you can see, I have some routing errors I cannot explain:

ActionController::RoutingError (No route matches [GET] "/javascripts/gmaps4rails/gmaps4rails.base.js"):
...
ActionController::RoutingError (No route matches [GET] "/javascripts/gmaps4rails/gmaps4rails.base.js"):
...
ActionController::RoutingError (No route matches [GET] "/javascripts/gmaps4rails/gmaps4rails.googlemaps.js"):
...
ActionController::RoutingError (No route matches [GET] "/javascripts/gmaps4rails/gmaps4rails.googlemaps.js"):
...

What I understand is that the ActionController do not have routes for /javascripts/gmaps4rails/gmaps4rails.base.js and /javascripts/gmaps4rails/gmaps4rails.googlemaps.js. However, I am surprised that few lines above the errors, the server can get these files from another path:

Started GET "/assets/gmaps4rails/gmaps4rails.base.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/gmaps4rails/gmaps4rails.base.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/gmaps4rails/gmaps4rails.googlemaps.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200
Started GET "/assets/gmaps4rails/gmaps4rails.googlemaps.js?body=1" for 127.0.0.1 at 2013-09-29 07:08:47 +0200

These errors do not interrupt the application. I mean the application executes well and render correct pages to the user, but these errors mean that something is wrong and I'd like to correct them before going further. Can anyone help solve this issue, thank you.


Solution

  • Finally, I've found how to fix this. In the Gemfile, I pointed to the git repo for gmaps4rails:

    # Gemfile
    gem 'gmaps4rails',
      require: 'gmaps4rails',
      git:     'git://github.com/apneadiving/Google-Maps-for-Rails.git'
    

    And I've run the gem install command: $> rails g gmaps4rails:install

    Here is the original answer: https://github.com/apneadiving/Google-Maps-for-Rails/issues/373