ali*_*lik 7 ruby-on-rails image heroku ruby-on-rails-3.1 asset-pipeline
我最近将我的Rails更新为3.1.
这是我添加的部分:
<%= asset_path('logo_symbol.png') %>
Run Code Online (Sandbox Code Playgroud)
这使得/assets/logo_symbol.png
它在开发环境中完美地工作.但是,当我将代码推送到heroku上的生产时,它会显示一个损坏的图像,其中包含url : assets/logo_symbol-135ddc8db2c9b59f032bed7db520137a.png
. 我猜这个新名字是出于一些优化的原因.
然而,值得注意的是,当我assets/logo_symbol-135ddc8db2c9b59f032bed7db520137a.png
在生产中访问网址时,我看到一个空白页面,但是当我将该网址更改为任意内容时,例如向其添加数字时,它会显示未找到的网页.很明显,它正在那个网址上找到一些东西.当我/assets/logo_symbol.png
直接进入production/heroku 时,它还会显示一个空白页面.
如果这是任何帮助,heroku不会在我推送代码时成功预编译,并且heroku的文档说明目前没有针对该问题的解决方法.
任何帮助都将非常感谢.
我的猜测是它与某些与环境相关的配置有关.我附上了我的application.rb,development.rb和production.rb文件的内容
这是我的production.rb文件的内容
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
#config.action_mailer.default_url_options = { :host => 'localhost:3000' }
#config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
end
module ActiveAdmin
class Reloader
def attach!
end
end
end
Run Code Online (Sandbox Code Playgroud)
这是我的development.rb文件的内容
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
#config.action_mailer.default_url_options = { :host => 'localhost:3000' }
#config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
end
module ActiveAdmin
class Reloader
def attach!
end
end
end
Run Code Online (Sandbox Code Playgroud)
以下是我的production.rb文件的内容
# Settings specified here will take precedence over those in config/application.rb
# The production environment is meant for finished, "live" apps.
# 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
# Specifies the header that your server uses for sending files
config.action_dispatch.x_sendfile_header = "X-Sendfile"
# For nginx:
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
# If you have no front-end server that supports something like X-Sendfile,
# just comment this out and Rails will serve the files
# See everything in the log (default is :info)
# config.log_level = :debug
# Use a different logger for distributed setups
# config.logger = SyslogLogger.new
# Use a different cache store in production
# config.cache_store = :mem_cache_store
# Disable Rails's static asset server
# In production, Apache or nginx will already do this
config.serve_static_assets = false
# Enable serving of images, stylesheets, and javascripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
#config.action_mailer.default_url_options = { :host => 'ha1.heroku.com' }
config.action_mailer.delivery_method = :smtp
# 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
# Compress JavaScripts and CSS
#config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
# Defaults to Rails.root.join("public/assets")
# config.assets.manifest = YOUR_PATH
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :scss
Run Code Online (Sandbox Code Playgroud)
我已经将配置文件与3.1的rails文档进行了比较,看起来我已经拥有了所有需要的默认值.但是我仍然没有看到任何形象.任何帮助都感激不尽
Ric*_*lse 13
从production.rb中删除此行:
config.action_dispatch.x_sendfile_header = "X-Sendfile"
您还应该将配置文件中的设置与管道指南的第9部分中的设置对齐.
Sendfile头包含上游Web服务器的信息,用于在何处查找文件(在文件系统上)以便为其提供服务.这将从后端(Rails/Sprockets)中移除负载.当sendfile打开时,HTTP响应中不包含任何正文(它是零长度),这就是为什么你什么也看不见.
在heroku上,nginx服务器无法访问应用程序文件系统,因此这不起作用.
请参阅Heroku dev site re sendfile上的这个注释.
如果您使用的是heroku,本文档概述了有效使用管道的最佳选择.
归档时间: |
|
查看次数: |
2960 次 |
最近记录: |