![](/img/trans.png)
[英]ActionController::RoutingError (No route matches [GET] “/javascripts/application.js”)
[英]Why I am getting this ActionController::RoutingError (No route matches [GET] “/users/assets/application.js”)
application.js 没有在生产中服务 heroku 我花了几天时间试图解决这个问题,在本地一切正常,但在 heroku 中,几乎没有什么东西根本不起作用。 比如link_to方法::delete
我的 heroku 日志 -t
vendor/bundle/ruby/2.6.0/gems/rack-1.6.13/lib/rack/lock.rb:17:in `call'
2020-12-30T01:07:53.712886+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/rack-1.6.13/lib/rack/content_length.rb:15:in `call'
2020-12-30T01:07:53.712886+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/rack-1.6.13/lib/rack/handler/webrick.rb:88:in `service'
2020-12-30T01:07:53.712887+00:00 app[web.1]: vendor/ruby-2.6.6/lib/ruby/2.6.0/webrick/httpserver.rb:140:in `service'
2020-12-30T01:07:53.712887+00:00 app[web.1]: vendor/ruby-2.6.6/lib/ruby/2.6.0/webrick/httpserver.rb:96:in `run'
2020-12-30T01:07:53.712888+00:00 app[web.1]: vendor/ruby-2.6.6/lib/ruby/2.6.0/webrick/server.rb:307:in `block in start_thread'
2020-12-30T01:07:53.712888+00:00 app[web.1]:
2020-12-30T01:07:53.712888+00:00 app[web.1]:
2020-12-30T01:07:53.717837+00:00 heroku[router]: at=info method=GET path="/users/assets/application.js" host=mobile-implant-lab.herokuapp.com request_id=882701e3-4706-4089-9a58-9bf704908181 fwd="24.85.18.207" dyno=web.1 connect=1ms service=11ms status=404 bytes=1829 protocol=https
2020-12-30T01:07:53.734605+00:00 heroku[router]: at=info method=GET path="/assets/application-c89e6fc7884f4c92e785833fd1c46c15f42f2c4a7845dd393b2f85c861554cdb.css" host=mobile-implant-lab.herokuapp.com request_id=b0740ac3-4a32-4d88-9afc-703ea284de67 fwd="24.85.18.207" dyno=web.1 connect=0ms service=6ms status=304 bytes=133 protocol=https
2020-12-30T01:07:53.746883+00:00 heroku[router]: at=info method=GET path="/assets/application-d360a99b8e1c4dc7c4dc2ed720b8c39d1234a60be3591c0d8c5dfee211e6d3ba.js" host=mobile-implant-lab.herokuapp.com request_id=1bfb3239-625a-4c36-8294-6b97685166db fwd="24.85.18.207" dyno=web.1 connect=1ms service=8ms status=304 bytes=133 protocol=https
2020-12-30T01:07:53.864359+00:00 app[web.1]: Started GET "/users/js/jquery-1.8.3.min.js" for 24.85.18.207 at 2020-12-30 01:07:53 +0000
2020-12-30T01:07:53.874958+00:00 app[web.1]:
2020-12-30T01:07:53.874962+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/users/js/jquery-1.8.3.min.js"):
2020-12-30T01:07:53.874963+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/actionpack-4.2.11.1/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
2020-12-30T01:07:53.874963+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/actionpack-4.2.11.1/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
2020-12-30T01:07:53.874964+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/railties-4.2.11.1/lib/rails/rack/logger.rb:38:in `call_app'
2020-12-30T01:07:53.874964+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/railties-4.2.11.1/lib/rails/rack/logger.rb:20:in `block in call'
2020-12-30T01:07:53.874965+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/activesupport-4.2.11.1/lib/active_support/tagged_logging.rb:68:in `block in tagged'
2020-12-30T01:07:53.874965+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/activesupport-4.2.11.1/lib/active_support/tagged_logging.rb:26:in `tagged'
2020-12-30T01:07:53.874966+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/activesupport-4.2.11.1/lib/active_support/tagged_logging.rb:68:in `tagged'
2020-12-30T01:07:53.874966+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/railties-4.2.11.1/lib/rails/rack/logger.rb:20:in `call'
2020-12-30T01:07:53.874967+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/actionpack-4.2.11.1/lib/action_dispatch/middleware/request_id.rb:21:in `call'
2020-12-30T01:07:53.874967+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/rack-1.6.13/lib/rack/methodoverride.rb:22:in `call'
2020-12-30T01:07:53.874968+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/rack-1.6.13/lib/rack/runtime.rb:18:in `call'
2020-12-30T01:07:53.874968+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/activesupport-4.2.11.1/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
2020-12-30T01:07:53.874969+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/actionpack-4.2.11.1/lib/action_dispatch/middleware/static.rb:120:in `call'
2020-12-30T01:07:53.874969+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/rack-1.6.13/lib/rack/sendfile.rb:113:in `call'
2020-12-30T01:07:53.874970+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/railties-4.2.11.1/lib/rails/engine.rb:518:in `call'
2020-12-30T01:07:53.874970+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/railties-4.2.11.1/lib/rails/application.rb:165:in `call'
2020-12-30T01:07:53.874971+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/rack-1.6.13/lib/rack/lock.rb:17:in `call'
2020-12-30T01:07:53.874971+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/rack-1.6.13/lib/rack/content_length.rb:15:in `call'
2020-12-30T01:07:53.874971+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/rack-1.6.13/lib/rack/handler/webrick.rb:88:in `service'
2020-12-30T01:07:53.874972+00:00 app[web.1]: vendor/ruby-2.6.6/lib/ruby/2.6.0/webrick/httpserver.rb:140:in `service'
2020-12-30T01:07:53.874972+00:00 app[web.1]: vendor/ruby-2.6.6/lib/ruby/2.6.0/webrick/httpserver.rb:96:in `run'
2020-12-30T01:07:53.874972+00:00 app[web.1]: vendor/ruby-2.6.6/lib/ruby/2.6.0/webrick/server.rb:307:in `block in start_thread'
2020-12-30T01:07:53.874973+00:00 app[web.1]:
2020-12-30T01:07:53.874973+00:00 app[web.1]:
2020-12-30T01:07:53.880600+00:00 heroku[router]: at=info method=GET path="/users/js/jquery-1.8.3.min.js" host=mobile-implant-lab.herokuapp.com request_id=b2f38529-db44-40ee-bd29-bcdfccb58b28 fwd="24.85.18.207" dyno=web.1 connect=1ms service=19ms status=404 bytes=1829 protocol=https
2020-12-30T01:07:53.881860+00:00 heroku[router]: at=info method=GET path="/assets/lubnasammanlogo-904d60f516b56d59a26594d28731f7538705be42c40533b6ac9a644b77bf66d6.png" host=mobile-implant-lab.herokuapp.com request_id=ef67c6e1-f686-4d74-b5ad-8fda93025820 fwd="24.85.18.207" dyno=web.1 connect=0ms service=20ms status=304 bytes=133 protocol=https
2020-12-30T01:07:53.903836+00:00 app[web.1]: Started GET "/users/assets/application.js" for 24.85.18.207 at 2020-12-30 01:07:53 +0000
2020-12-30T01:07:53.906478+00:00 app[web.1]:
2020-12-30T01:07:53.906480+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/users/assets/application.js"):
2020-12-30T01:07:53.906505+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/actionpack-4.2.11.1/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
2020-12-30T01:07:53.906506+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/actionpack-4.2.11.1/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
2020-12-30T01:07:53.906506+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/railties-4.2.11.1/lib/rails/rack/logger.rb:38:in `call_app'
2020-12-30T01:07:53.906507+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/railties-4.2.11.1/lib/rails/rack/logger.rb:20:in `block in call'
2020-12-30T01:07:53.906507+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/activesupport-4.2.11.1/lib/active_support/tagged_logging.rb:68:in `block in tagged'
2020-12-30T01:07:53.906508+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/activesupport-4.2.11.1/lib/active_support/tagged_logging.rb:26:in `tagged'
2020-12-30T01:07:53.906508+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/activesupport-4.2.11.1/lib/active_support/tagged_logging.rb:68:in `tagged'
2020-12-30T01:07:53.906509+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/railties-4.2.11.1/lib/rails/rack/logger.rb:20:in `call'
2020-12-30T01:07:53.906509+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/actionpack-4.2.11.1/lib/action_dispatch/middleware/request_id.rb:21:in `call'
2020-12-30T01:07:53.906510+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/rack-1.6.13/lib/rack/methodoverride.rb:22:in `call'
2020-12-30T01:07:53.906511+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/rack-1.6.13/lib/rack/runtime.rb:18:in `call'
2020-12-30T01:07:53.906511+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/activesupport-4.2.11.1/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
2020-12-30T01:07:53.906521+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/actionpack-4.2.11.1/lib/action_dispatch/middleware/static.rb:120:in `call'
2020-12-30T01:07:53.906522+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/rack-1.6.13/lib/rack/sendfile.rb:113:in `call'
2020-12-30T01:07:53.906522+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/railties-4.2.11.1/lib/rails/engine.rb:518:in `call'
2020-12-30T01:07:53.906522+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/railties-4.2.11.1/lib/rails/application.rb:165:in `call'
2020-12-30T01:07:53.906523+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/rack-1.6.13/lib/rack/lock.rb:17:in `call'
2020-12-30T01:07:53.906523+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/rack-1.6.13/lib/rack/content_length.rb:15:in `call'
2020-12-30T01:07:53.906524+00:00 app[web.1]: vendor/bundle/ruby/2.6.0/gems/rack-1.6.13/lib/rack/handler/webrick.rb:88:in `service'
2020-12-30T01:07:53.906524+00:00 app[web.1]: vendor/ruby-2.6.6/lib/ruby/2.6.0/webrick/httpserver.rb:140:in `service'
2020-12-30T01:07:53.906525+00:00 app[web.1]: vendor/ruby-2.6.6/lib/ruby/2.6.0/webrick/httpserver.rb:96:in `run'
2020-12-30T01:07:53.906525+00:00 app[web.1]: vendor/ruby-2.6.6/lib/ruby/2.6.0/webrick/server.rb:307:in `block in start_thread'
Here my production.rb
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
config.serve_static_files = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like
# NGINX, varnish or squid.
# config.action_dispatch.rack_cache = true
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
# Compress JavaScripts and CSS.
config.assets.js_compressor = Uglifier.new(harmony: true)
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = true
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
config.assets.digest = true
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = :debug
# Prepend all log lines with the following tags.
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups.
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
config.assets.raise_runtime_errors = true
end
我的 application.js
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require bootstrap-sprockets
//= require sweetalert2
//= require sweet-alert2-rails
//= require cocoon
//= require sweet-alert-confirm
我的应用程序.html.erb
<!DOCTYPE html>
<html>
<head>
<title>MobileImplantLab</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', "data-turbolinks-track" => true%>
<%= csrf_meta_tags %>
<%= favicon_link_tag 'favicon.ico' %>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
这是我的 Gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.11.1'
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.20.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
gem 'devise'
group :development, :test do
gem "interactive_editor"
gem "hirb"
gem "awesome_print"
gem 'byebug'
end
gem 'rails_12factor'
gem 'mail_form'
gem 'font-awesome-sass', '~> 5.12.0'
gem 'bootsnap', '>= 1.1.0', require: false
gem 'bootstrap-sass', '~>3.2.0'
gem "paperclip"
gem 'aws-sdk-s3'
gem 'aws-sdk', '< 2.0'
gem 'thor', '0.19.1'
gem 'google-api-client', require: 'google/apis/calendar_v3'
gem 'omniauth-google-oauth2'
gem "recaptcha", require: "recaptcha/rails"
gem 'friendly_id', '~> 5.4.0'
gem 'activeadmin'
gem 'rails-assets-sweetalert2', source: 'https://rails-assets.org'
gem 'sweet-alert2-rails'
gem 'sweet-alert-confirm'
gem "cocoon"
gem 'bigdecimal', '1.3.5'
gem 'bundler', '1.17.3'
在应用程序.rb
require File.expand_path('../boot', __FILE__)
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module MobileImplantLab
class Application < Rails::Application
config.assets.initialize_on_precompile = false
config.assets.paths << "#{Rails.root}/app/assets/videos"
# 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.
# 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
# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true
end
end
我试图运行这个命令
$ heroku run rake assets:precompile
Running rake assets:precompile on ⬢ mobile-implant-lab... up, run.8931 (Standard-1X)
/app/vendor/bundle/ruby/2.6.0/gems/activesupport-4.2.11.1/lib/active_support/core_ext/object/duplicable.rb:111: warning: BigDecimal.new is deprecated; use BigDecimal() method instead.
I, [2020-12-28T19:46:55.818346 #4] INFO -- : Writing /app/public/assets/application-e57be3269d79ff2275ae1cbfec657d777c6e4dc7d27f3ba5feaeebfdee1ba0c4.js
I, [2020-12-28T19:46:55.818855 #4] INFO -- : Writing /app/public/assets/application-e57be3269d79ff2275ae1cbfec657d777c6e4dc7d27f3ba5feaeebfdee1ba0c4.js.gz
任何帮助将不胜感激
Heruku 在容器内运行应用程序,这与在本地或裸机服务器上运行不同。 例如 - 您的应用程序在其源旁边写入“磁盘”的任何文件都会在某个时间点丢失,并且这些文件在容器实例之间也不可见。 所以通过heroku run
运行远程预编译不会有任何效果。
确保public/assets
中的任何内容都没有提交(或提交)到存储库,因此 heroku 将尝试在 slug 构建阶段运行预编译。 其他选项则相反 - 如果您的资产很少更改且很小 - 您可以在本地编译后提交整个public/assets
。 请参阅heroku 文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.