我在 Rails 服务器上使用 Opal 将 Ruby 转换为 Javascript,并且在开发和生产模式下,一切都在我本地机器上的测试服务器上完美运行。但是,当文件上传到实际服务器时,ActionView::Template::Error
会生成一条 with no 消息。它指示的行是加载 Javascript (Opal) 的行,实际上,当删除该行时,错误就会消失(尽管这显然不是解决方案)。服务器上的所有文件都与本地机器上的文件相同,除了bin
文件夹和文件。db
log
tmp
Gemfile.lock
我认为这可能是一个缓存问题,因为最初只有已更改的文件不起作用,但我不能确定,因为现在所有文件都已损坏。
我试过删除tmp
文件夹,使用gem pristine --all
和使用gem update
,但这些都没有帮助。
我一直在寻找解决方案,但没有错误消息,我不知道从哪里开始。
此外,该服务器之前确实可以工作,但最近的更改(将脚本转换为 Opal)破坏了它。
这是错误日志中许多类似的错误消息之一:
I, [2016-09-15T11:24:58.760385 #18949] INFO -- : [36ec2f26-e1ac-43a1-b3c9-2e211c80bedb] Started GET "/" for 123.211.235.196 at 2016-09-15 11:24:58 +0000
I, [2016-09-15T11:24:58.762917 #18949] INFO -- : [36ec2f26-e1ac-43a1-b3c9-2e211c80bedb] Processing by WelcomeController#index as HTML
I, [2016-09-15T11:24:58.766164 #18949] INFO -- : [36ec2f26-e1ac-43a1-b3c9-2e211c80bedb] Rendering welcome/index.haml within layouts/application
I, [2016-09-15T11:24:58.768033 #18949] INFO -- : [36ec2f26-e1ac-43a1-b3c9-2e211c80bedb] Rendered welcome/index.haml within layouts/application (1.7ms)
I, [2016-09-15T11:25:15.383874 #18949] INFO -- : [36ec2f26-e1ac-43a1-b3c9-2e211c80bedb] Completed 500 Internal Server Error in 16620ms (ActiveRecord: 0.0ms)
F, [2016-09-15T11:25:15.388426 #18949] FATAL -- : [36ec2f26-e1ac-43a1-b3c9-2e211c80bedb]
F, [2016-09-15T11:25:15.388528 #18949] FATAL -- : [36ec2f26-e1ac-43a1-b3c9-2e211c80bedb] ActionView::Template::Error ():
F, [2016-09-15T11:25:15.388756 #18949] FATAL -- : [36ec2f26-e1ac-43a1-b3c9-2e211c80bedb] 4: = csrf_meta_tags
F, [2016-09-15T11:25:15.388803 #18949] FATAL -- : [36ec2f26-e1ac-43a1-b3c9-2e211c80bedb] 5: = favicon_link_tag '/favicon.ico'
F, [2016-09-15T11:25:15.388842 #18949] FATAL -- : [36ec2f26-e1ac-43a1-b3c9-2e211c80bedb] 6: = stylesheet_link_tag params[:controller], media: 'all'
F, [2016-09-15T11:25:15.388880 #18949] FATAL -- : [36ec2f26-e1ac-43a1-b3c9-2e211c80bedb] 7: = javascript_include_tag params[:controller]
F, [2016-09-15T11:25:15.388917 #18949] FATAL -- : [36ec2f26-e1ac-43a1-b3c9-2e211c80bedb] 8: = yield :head
F, [2016-09-15T11:25:15.388953 #18949] FATAL -- : [36ec2f26-e1ac-43a1-b3c9-2e211c80bedb] 9: %body.standard{ class: [yield(:body_class), params[:controller]] }
F, [2016-09-15T11:25:15.388991 #18949] FATAL -- : [36ec2f26-e1ac-43a1-b3c9-2e211c80bedb] 10: #wrapper= yield
F, [2016-09-15T11:25:15.389028 #18949] FATAL -- : [36ec2f26-e1ac-43a1-b3c9-2e211c80bedb]
F, [2016-09-15T11:25:15.389064 #18949] FATAL -- : [36ec2f26-e1ac-43a1-b3c9-2e211c80bedb] app/views/layouts/application.haml:7:in `_app_views_layouts_application_haml__2281947942353102831_69956393327940'
我config/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
# 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
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = true
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'
# 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
# Mount Action Cable outside main process or domain
# config.action_cable.mount_path = nil
# config.action_cable.url = 'wss://example.com/cable'
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
# 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 = [ :request_id ]
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "ontonator_xyz_#{Rails.env}"
config.action_mailer.perform_caching = false
# 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
# Use a different logger for distributed setups.
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
end
编辑:
我现在可以确认它是 Opal。再次使用 CoffeeScript 可以防止问题发生。
另外,这个问题现在出现在我的本地机器上,我认为这是因为编译文件的缓存是在开发模式下生成的,而这些缓存是在生产模式下使用的。由于我没有在服务器上以开发模式进行测试,所以我没有意识到。
设置config.consider_all_requests_local = true
解决了这个问题,它在被删除后继续工作,但一旦任何相关的 Javascript 资产被修改,它就会停止工作。
也许我错了,但config.assets.compile = true
如果它们没有预编译,不应该让服务器编译资产?
编辑2:
它也适用于预编译资产,但我不明白为什么这对于config.assets.compile = true
选项集是必要的。