我需要帮助来解决我的应用程序的资产管道问题。任何人都可以看看我缺少的东西吗?提前致谢。
我正在使用以下rails 3.2.13,ruby 1.9.3(用于开发)和ruby 2.0.0(用于heroku上的生产)。 (我在生产中使用不同版本的ruby作为一个名为bybosa的宝石无法与ruby的开发版本一起安装......我不确定这是否是问题的根源。可能不是......)。
我预先编译了本地运行的资产:bundle exec rake assets:precompile RAILS_ENV = production。资产得到很好的预编译并放在public / assets /目录中。但是,此过程运行时出现错误:"无法转储匿名类"错误。这似乎与sass和sprockets有关......但编译完成后放在public / assets目录中的文件。原始图像,以及具有长哈希扩展的相同图像名称。我承诺一切git并从git部署到heroku。 Heroku不运行资产编译,因为public / assets目录中有一个清单文件。
应用程序部署得很好,但图像无法正常提供。提供CSS和JS。布局的样式至少是预期的。所以CSS和JS没问题(我可以注意到)。 仅提供两张图片。其他10张图片均未送达。 Heroku日志显示找不到这些图像的错误404。这些图像的路径是/ assets / image_name。提供的两个映像具有这些路径/ assets / image_name + hash(在预编译操作期间由资产管道生成的字母和数字的组合)。检查网页上的元素时,只有那两个显示的图像在图像名称后面有长哈希。所有其他图片都没有哈希... 我想知道为什么网络服务器无法找到其他图像。为什么Web服务器没有通过具有长哈希扩展的资产管道将图像指向为预编译?
在开发环境中,所有图像都能很好地显示出来。这里,图像由其简单名称引用(没有资产管道扩展)。
github app:https://github.com/mazembo/cdhuk
我的宝石文件:
source 'http://rubygems.org'
ruby "2.0.0"
gem 'rails', '3.2.13'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development, :test, :production do
# gem 'sqlite3'
gem 'pg'
end
# Gems used only for assets and not required
# in production environments by default.
#group :assets do
# gem 'sass-rails', '~> 3.2.3'
# gem 'coffee-rails', '~> 3.2.1'
# gem 'twitter-bootstrap-rails'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
#end
# Use SCSS for stylesheets
gem 'bootstrap-sass', '3.1.1.0'
gem 'sass-rails', '>= 3.2'
gem 'jquery-rails'
gem 'turbolinks'
gem 'rails_12factor', group: :production
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
# Refinery CMS
gem 'refinerycms', '~> 2.1.0'
# Optionally, specify additional Refinery CMS Extensions here:
gem 'refinerycms-acts-as-indexed', '~> 1.0.0'
gem 'refinerycms-blog', '~> 2.1.0'
gem 'refinerycms-inquiries', '~> 2.1.0'
gem 'refinerycms-search', '~> 2.1.0'
gem 'refinerycms-page-images', '~> 2.1.0'
gem "refinerycms-news", '~> 2.1.0'
#gem 'refinerycms-portfolio', :git => 'git://github.com/refinery /refinerycms-portfolio.git', :branch => '2-0-stable'
gem' refinerycms-videojs' #gem' refinerycms-memberships',' 2.0' #gem' refinerycms-calendar','〜> 2.0.0' #gem' refinerycms-bootstrap',:github => ' fernandoaleman / refinerycms- bootstrap' ,: branch => '主' 组:发展做 宝石' jazz_hands' 端
我的config / application.rb文件:
需要File.expand_path(' ../ boot', FILE )
# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
if defined?(Bundler)
# If you precompile assets before deploying to production, use line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
module Renaissance2
class Application < Rails::Application
# 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.
# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
# 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
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
# Enable escaping HTML in JSON.
config.active_support.escape_html_entities_in_json = true
# Use SQL instead of Active Record's schema dumper when creating the database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql
# Enforce whitelist mode for mass assignment.
# This will create an empty whitelist of attributes available for mass-assignment for all models
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
# parameters by using an attr_accessible or attr_protected declaration.
config.active_record.whitelist_attributes = true
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
config.assets.initialize_on_precompile = true
end
end
我的配置/环境/ production.rb
Renaissance2::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
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = true
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true
# Generate digests for assets URLs
config.assets.digest = true
# Defaults to nil and saved in location specified by
config.assets.prefix
# config.assets.manifest = YOUR_PATH
# 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
#for heroku
config.action_dispatch.x_sendfile_header = nil
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# See everything in the log (default is :info)
# 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"
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )
# Disable delivery errors, bad email addresses will be ignored
if config.respond_to?(:action_mailer)
# config.action_mailer.raise_delivery_errors = false
end
# Enable threaded mode
# config.threadsafe!
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
end
我尝试过但没有成功: