我的应用程序在开发环境中工作,但在Heroku中有一些图像,字体和js函数无效。
我现在要在一张图片上磨练。主页应加载位于
的图像资产/图像/图形/ blue_pattern.gif
在我的SCSS文件中,我有:
image-url("patterns/blue_pattern.gif")
我的Heroku日志包含以下内容:
2017-04-11T10:39:54.873200 + 00:00 heroku [router]:at = info method = GET 路径= “/图片/图形/ blue_pattern.gif” 主机= matchmeplease.herokuapp.com request_id = cf0c2d58-a616-484f-b659-cd4cbfe94118 fwd =“115.70.240.190” dyno = web.1 connect = 2ms service = 5ms status = 404 bytes = 1789 协议= HTTPS
我会诚实地说我不完全理解配置文件。
我的config / environments / production.rb文件:
Rails.application.configure do
config.force_ssl = true
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.public_file_server.enabled = false
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
config.assets.compile = true
config.assets.digest = true
config.log_level = :debug
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
config.serve_static_assets = true
end
配置/ application.rb中:
require_relative 'boot'
require 'rails/all'
require 'geocoder'
require "geocoder/railtie"
Geocoder::Railtie.insert
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module MatchMe
class Application < Rails::Application
config.assets.paths << Rails.root.join("app", "assets", "font")
end
end
编辑:在关注Uday kumar das'评论后(见下文)我现在有图像和字体工作,但我的js文件由于某种原因仍然没有加载。
当我运行RAILS_ENV=production bundle exec rake assets:precompile
时,我得到以下内容:
rake aborted!
ArgumentError: Missing required arguments: aws_access_key_id, aws_secret_access_key
/usr/local/rvm/gems/ruby-2.3.0/gems/fog-core-1.43.0/lib/fog/core/service.rb:244:in `validate_options'
/usr/local/rvm/gems/ruby-2.3.0/gems/fog-core-1.43.0/lib/fog/core/service.rb:268:in `handle_settings'
/usr/local/rvm/gems/ruby-2.3.0/gems/fog-core-1.43.0/lib/fog/core/service.rb:98:in `new'
/usr/local/rvm/gems/ruby-2.3.0/gems/fog-core-1.43.0/lib/fog/core/services_mixin.rb:16:in `new'
/usr/local/rvm/gems/ruby-2.3.0/gems/fog-core-1.43.0/lib/fog/storage.rb:27:in `new'
/usr/local/rvm/gems/ruby-2.3.0/gems/carrierwave-0.11.2/lib/carrierwave/uploader/configuration.rb:83:in `eager_load_fog'
/usr/local/rvm/gems/ruby-2.3.0/gems/carrierwave-0.11.2/lib/carrierwave/uploader/configuration.rb:96:in `fog_credentials='
/home/ubuntu/workspace/matchme/config/initializers/carrier_wave.rb:5:in `block in <top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/gems/carrierwave-0.11.2/lib/carrierwave/uploader/configuration.rb:118:in `configure'
/usr/local/rvm/gems/ruby-2.3.0/gems/carrierwave-0.11.2/lib/carrierwave.rb:14:in `configure'
/home/ubuntu/workspace/matchme/config/initializers/carrier_wave.rb:4:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `block in load'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/engine.rb:648:in `block in load_config_initializer'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/notifications.rb:166:in `instrument'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/engine.rb:647:in `load_config_initializer'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/engine.rb:612:in `block (2 levels) in <class:Engine>'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/engine.rb:611:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/engine.rb:611:in `block in <class:Engine>'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:30:in `instance_exec'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:30:in `run'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:55:in `block in run_initializers'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:44:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:44:in `tsort_each_child'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:54:in `run_initializers'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/application.rb:352:in `initialize!'
/home/ubuntu/workspace/matchme/config/environment.rb:5:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/application.rb:328:in `require_environment!'
/usr/local/rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/application.rb:448:in `block in run_tasks_blocks'
/usr/local/rvm/gems/ruby-2.3.0/gems/sprockets-rails-3.2.0/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => environment
(See full trace by running task with --trace)
我不确定为什么这是因为我的AWS S3功能在我的应用程序中完美运行。
答案 0 :(得分:1)
在config/application.rb
添加以下代码并bundle
添加:
config.serve_static_assets = true
gem 'rails_12factor', group: :production
此次运行后RAILS_ENV=production bundle exec rake assets:precompile
。
有关详细信息,请访问https://devcenter.heroku.com/articles/rails-4-asset-pipeline