【问题标题】:Different page appearence when deploying to Heroku部署到 Heroku 时的不同页面外观
【发布时间】:2013-02-22 15:35:11
【问题描述】:

我尝试使用一些Kendo UI 小部件,它们在开发中运行良好。但是当我将我的应用部署到 Heroku 时,它的外观发生了巨大变化。

我编写了一个带有 TreeView 小部件的示例页面。这是它在开发中的呈现方式:

在 Heroku 上的生产中:

可以看出,列表标记(树标记?)不见了。

我怀疑这个问题与资产管道有关,因为这样做rake assets:precompile 也会破坏开发中的东西(并且rake assets:clean 会将其恢复)。但这让我感到困惑,因为我的 Bootstrap 标头在开发和生产中都可以正常工作(尽管 Heroku 日志中有一些 ActionController::RoutingError (No route matches [GET] "/assets/Bootstrap/loading.gif") 错误)。

宝石文件

source 'https://rubygems.org'

gem 'rails'
gem "ancestry"
gem "bootstrap-sass"
gem "will_paginate"
gem "bootstrap-will_paginate"
gem "truncate_html"
gem "slim-rails"
gem "kendoui-rails"

group :development, :test do
  gem 'sqlite3'
  gem 'rspec-rails'
  gem "minitest"

  platform :ruby do
    gem 'therubyracer'
  end
end

group :test do
  gem 'capybara'
end

group :development do
  gem "nifty-generators"
  gem "annotate"
end

group :production do
  gem 'pg'
end

group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails', '~> 2.1.3'

gem 'bcrypt-ruby', require: 'bcrypt'

development.rb

config.cache_classes = false
config.whiny_nils = true
config.consider_all_requests_local       = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
config.action_dispatch.best_standards_support = :builtin
config.active_record.mass_assignment_sanitizer = :strict
config.active_record.auto_explain_threshold_in_seconds = 0.5
config.assets.compress = false
config.assets.debug = true

production.rb

config.cache_classes = true
config.consider_all_requests_local       = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = false
config.assets.digest = true
config.i18n.fallbacks = true
config.active_support.deprecation = :notify

有谁知道如何解决这个问题?任何帮助表示赞赏。


更新 1

感谢大家的cmets,这里是附加信息。

Heroku 日志:

2013-02-23T02:37:50+00:00 app[web.1]: Started GET "/environment_test/index" for 193.169.36.82 at 2013-02-23 02:37:50 +0000
2013-02-23T02:37:50+00:00 app[web.1]: Processing by EnvironmentTestController#index as HTML
2013-02-23T02:37:50+00:00 app[web.1]:   Rendered environment_test/index.html.slim within layouts/application (23.3ms)
2013-02-23T02:37:50+00:00 app[web.1]:   Rendered layouts/_header.slim (57.2ms)
2013-02-23T02:37:50+00:00 app[web.1]: Completed 200 OK in 159ms (Views: 158.7ms | ActiveRecord: 0.0ms)
2013-02-23T02:37:50+00:00 heroku[router]: at=info method=GET path=/environment_test/index host=biotriz.herokuapp.com fwd="193.169.36.82" dyno=web.1 queue=0 wait=2ms connect=20ms service=394ms status=200 bytes=1253
2013-02-23T02:37:50+00:00 heroku[router]: at=info method=GET path=/assets/application-43a283ce09b9af356379df3e89b8b1cc.css host=biotriz.herokuapp.com fwd="193.169.36.82" dyno=web.1 queue=0 wait=0ms connect=1ms service=10ms status=200 bytes=186674
2013-02-23T02:37:51+00:00 heroku[router]: at=info method=GET path=/assets/application-8ac08b06d5d57f91da7af9d1e1c345c0.js host=biotriz.herokuapp.com fwd="193.169.36.82" dyno=web.1 queue=0 wait=7ms connect=20ms service=64ms status=200 bytes=648803
2013-02-23T02:37:55+00:00 heroku[router]: at=info method=GET path=/favicon.ico host=biotriz.herokuapp.com fwd="193.169.36.82" dyno=web.1 queue=0 wait=0ms connect=0ms service=5ms status=200 bytes=0
2013-02-23T02:37:55+00:00 app[web.1]: Started GET "/environment_test/index.json" for 193.169.36.82 at 2013-02-23 02:37:55 +0000
2013-02-23T02:37:55+00:00 app[web.1]: Processing by EnvironmentTestController#index as JSON
2013-02-23T02:37:55+00:00 heroku[router]: at=info method=GET path=/assets/glyphicons-halflings-white-6cccd17a7aed91dbc0157d343c68c0d9.png host=biotriz.herokuapp.com fwd="193.169.36.82" dyno=web.1 queue=0 wait=0ms connect=3ms service=66ms status=200 bytes=8777
2013-02-23T02:37:55+00:00 app[web.1]: Completed 200 OK in 104ms (Views: 0.6ms | ActiveRecord: 31.9ms)
2013-02-23T02:37:55+00:00 app[web.1]: Started GET "/assets/Bootstrap/loading.gif" for 193.169.36.82 at 2013-02-23 02:37:55 +0000
2013-02-23T02:37:55+00:00 app[web.1]: 
2013-02-23T02:37:55+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/assets/Bootstrap/loading.gif"):
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/rack/logger.rb:32:in `call_app'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/rack/logger.rb:16:in `block in call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/tagged_logging.rb:22:in `tagged'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/rack/logger.rb:16:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_dispatch/middleware/request_id.rb:22:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/methodoverride.rb:21:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/runtime.rb:17:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
2013-02-23T02:37:55+00:00 heroku[router]: at=info method=GET path=/assets/Bootstrap/loading.gif host=biotriz.herokuapp.com fwd="193.169.36.82" dyno=web.1 queue=0 wait=1ms connect=12ms service=56ms status=404 bytes=728
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/lock.rb:15:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_dispatch/middleware/static.rb:62:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:136:in `forward'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:245:in `fetch'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:185:in `lookup'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:66:in `call!'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:51:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:479:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/application.rb:223:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/content_length.rb:14:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/rack/log_tailer.rb:17:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/handler/webrick.rb:59:in `service'
2013-02-23T02:37:55+00:00 app[web.1]:   /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
2013-02-23T02:37:55+00:00 app[web.1]:   /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
2013-02-23T02:37:55+00:00 app[web.1]:   /usr/local/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
2013-02-23T02:37:55+00:00 app[web.1]: 
2013-02-23T02:37:55+00:00 app[web.1]: 
2013-02-23T02:37:55+00:00 heroku[router]: at=info method=GET path=/environment_test/index.json host=biotriz.herokuapp.com fwd="193.169.36.82" dyno=web.1 queue=0 wait=6ms connect=16ms service=121ms status=200 bytes=390
2013-02-23T02:37:55+00:00 app[web.1]: Started GET "/assets/Bootstrap/sprite.png" for 193.169.36.82 at 2013-02-23 02:37:55 +0000
2013-02-23T02:37:55+00:00 app[web.1]: 
2013-02-23T02:37:55+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/assets/Bootstrap/sprite.png"):
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/rack/logger.rb:32:in `call_app'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/rack/logger.rb:16:in `block in call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/tagged_logging.rb:22:in `tagged'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/rack/logger.rb:16:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_dispatch/middleware/request_id.rb:22:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/methodoverride.rb:21:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/runtime.rb:17:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/lock.rb:15:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_dispatch/middleware/static.rb:62:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:136:in `forward'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:245:in `fetch'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:185:in `lookup'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:66:in `call!'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:51:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:479:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/application.rb:223:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/content_length.rb:14:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/rack/log_tailer.rb:17:in `call'
2013-02-23T02:37:55+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/handler/webrick.rb:59:in `service'
2013-02-23T02:37:55+00:00 app[web.1]:   /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
2013-02-23T02:37:55+00:00 app[web.1]:   /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
2013-02-23T02:37:55+00:00 app[web.1]:   /usr/local/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
2013-02-23T02:37:55+00:00 app[web.1]: 
2013-02-23T02:37:55+00:00 app[web.1]: 
2013-02-23T02:37:55+00:00 heroku[router]: at=info method=GET path=/assets/Bootstrap/sprite.png host=biotriz.herokuapp.com fwd="193.169.36.82" dyno=web.1 queue=0 wait=0ms connect=1ms service=7ms status=404 bytes=728
2013-02-23T02:38:19+00:00 app[web.1]: Started GET "/environment_test/index.json?id=33" for 193.169.36.82 at 2013-02-23 02:38:19 +0000
2013-02-23T02:38:19+00:00 app[web.1]: Processing by EnvironmentTestController#index as JSON
2013-02-23T02:38:19+00:00 app[web.1]:   Parameters: {"id"=>"33"}
2013-02-23T02:38:19+00:00 app[web.1]: Completed 200 OK in 17ms (Views: 0.4ms | ActiveRecord: 14.0ms)
2013-02-23T02:38:19+00:00 heroku[router]: at=info method=GET path=/environment_test/index.json?id=33 host=biotriz.herokuapp.com fwd="193.169.36.82" dyno=web.1 queue=0 wait=0ms connect=1ms service=26ms status=200 bytes=266

在我的清单 CSS 文件 (application.css) 中包含两个与 Kendo 相关的 CSS 文件:kendo.common.min.css(包含公共代码,@ 987654323@) 和 kendo.bootstrap.min.css(主题特定代码,unminified version)。

顺便提一下,kendoui-rails gem 中的vendor 目录结构如下:

vendor
└── assets
    ├── javascripts
    │   └── ...
    └── stylesheets
        └── kendo
            ├── Bootstrap
            │   ├── editor.png
            │   ├── imagebrowser.png
            │   ├── loading.gif
            │   ├── loading-image.gif
            │   ├── slider-h.gif
            │   ├── slider-v.gif
            │   └── sprite.png
            ├── ... # Some other theme-specific dirs
            ├── kendo.bootstrap.min.css
            ├── kendo.common.min.css
            └── ... # Some other theme-specific CSS's

文件 kendo.bootstrap.min.css 包含引用图像(url('Bootstrap/sprite.png')url('Bootstrap/loading.gif'))的代码,这些图像未在生产中显示(但它们存在于 Bootstrap目录),所以我认为 Chris Rueber 是正确的。那么我该如何解决呢?

【问题讨论】:

  • 请发布您的 Heroku 日志,以便我们解决预编译错误。
  • 我同意您对它作为资产管道事物的评估。 CSS 中如何引用图像(箭头/指示符)?乍一看,这听起来像是 CSS 可能通过 ../images/arrow-left.jpg 类型的引用来引用的东西,当它在资产管道中时它不能正常工作。
  • @Jesper,我添加了日志。
  • @ChrisRueber,我更新了我的帖子。
  • 我已经(几乎)在我的机器上复制了您的代码,如果 gem 安装了 KendoUI,似乎没有添加 css 文件,可能它们作为引擎包含在内。请告诉我们您是如何安装 Kendo UI 的。

标签: ruby-on-rails heroku asset-pipeline


【解决方案1】:

Bootstrap 文件夹移动到vendor/assets/images(如果不存在,则创建它)。查看http://guides.rubyonrails.org/asset_pipeline.html#css-and-sass 了解更多信息。

【讨论】:

  • 谢谢你的回答,我明天试试。
【解决方案2】:

实际上问题在the issuesKendoUI-Rails github 存储库中进行了描述。由于合并了 css 文件,它似乎在预编译 assets 后出现。这样,.png 文件的正确路径就会丢失。您可以通过关闭调试来重现生产中的错误,如下所示(在您的development.rb 中):

config.assets.debug = false

一种可能的解决方法是将.css 文件与资产管道分开,如下所示:

<link rel="stylesheet" href="../assets/kendo/kendo.bootstrap.min.css">

但是,正如票据@fadzlan 的作者所解释的那样,这将导致css 资产由application server 提供,而不是web server

【讨论】:

  • 谢谢。我实际上应该自己检查问题跟踪器。
猜你喜欢
  • 2016-05-02
  • 2023-03-30
  • 1970-01-01
  • 1970-01-01
  • 2021-05-13
  • 2012-01-01
  • 1970-01-01
  • 2020-02-17
  • 1970-01-01
相关资源
最近更新 更多