Rails服务器:没有路由匹配javascript资产

时间:2013-09-29 05:49:51

标签: ruby-on-rails-4 asset-pipeline gmaps4rails

我在我的应用程序中使用Ruby 2和Rails 4。我已经安装了gmaps4rails gem,并将其资产从lib / assets移动到vendor / assets(样式表和javascripts目录)。 使用gmaps4rails的控制器称为FieldsController。 以下是我的代码:

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

gmaps4rails是vendor / assets / javascripts中的目录。

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

gmaps4rails.css是vendor / assets / stylesheets中的文件。

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

当我启动rails服务器并移动到Fields索引页面时,我有以下日志:

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'

正如您所看到的,我有一些无法解释的路由错误:

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"):
...

据我所知,ActionController没有/javascripts/gmaps4rails/gmaps4rails.base.js和/javascripts/gmaps4rails/gmaps4rails.googlemaps.js的路由。但是,我很惊讶在错误之上只有几行,服务器可以从另一条路径获取这些文件:

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

这些错误不会中断应用程序。我的意思是应用程序执行良好并向用户呈现正确的页面,但这些错误意味着出现了问题,我想在进一步说明之前纠正它们。 任何人都可以帮助解决这个问题,谢谢。

1 个答案:

答案 0 :(得分:0)

最后,我发现了如何解决这个问题。 在Gemfile中,我指向了gmaps4rails的git repo:

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

我运行了gem install命令:     $&GT; rails g gmaps4rails:install

以下是原始答案:https://github.com/apneadiving/Google-Maps-for-Rails/issues/373