简体   繁体   English

Heroku不提供资产文件

[英]Heroku not serving files from assets

I'm trying out Heroku as a host for our current Rails 4.0.0 project. 我正在尝试将Heroku作为我们当前的Rails 4.0.0项目的主机。 Although this seems to be a regular issue for Heroku users, none of the solutions that I have found have made any difference for me. 尽管对于Heroku用户来说这似乎是一个经常性的问题,但是我发现的所有解决方案都对我没有任何影响。

The server is not serving up any of our images, css, or js from our assets. 服务器未提供我们资产中的任何图像,css或js。

I've tried adding gems: 我尝试添加宝石:

gem 'rails_log_stdout',           github: 'heroku/rails_log_stdout'
gem 'rails3_serve_static_assets', github: 'heroku/rails3_serve_static_assets'
gem 'rails_12factor'

and setting the config options in production.rb to: 并将production.rb的配置选项设置为:

config.action_dispatch.x_sendfile_header = "X-Accel-Redirect"
config.serve_static_assets = true
config.assets.initialize_on_precompile = false

in various combinations but the server still will not load any of the assets. 各种组合,但服务器仍不会加载任何资产。

To be clear, and in case I've missed anything simple, I'm making these changes, committing the code to GitHub, then executing git push staging master . 明确地说,以防万一我错过了任何简单的事情,我正在进行这些更改,将代码提交到GitHub,然后执行git push staging master My development machine is a Windows 8 machine. 我的开发机器是Windows 8机器。

EDIT Here is the output from executing git push staging master : 编辑这是执行git push staging master的输出:

Counting objects: 11, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 569 bytes, done.
Total 6 (delta 4), reused 0 (delta 0)

-----> Ruby/Rails app detected
-----> Using Ruby version: ruby-2.0.0
-----> Installing dependencies using Bundler version 1.3.2
       Running: bundle install --without development:test --path vendor/bundle -
-binstubs vendor/bundle/bin
       Updating git://github.com/milgner/compass-rails.git
       Fetching gem metadata from https://rubygems.org/..........
       Fetching gem metadata from https://rubygems.org/..
       Resolving dependencies...
       Using rake (10.1.0)
       Using i18n (0.6.4)
       Using minitest (4.7.5)
       Using multi_json (1.7.7)
       Using atomic (1.1.10)
       Using thread_safe (0.1.0)
       Using tzinfo (0.3.37)
       Using activesupport (4.0.0)
       Using builder (3.1.4)
       Using erubis (2.7.0)
       Using rack (1.5.2)
       Using rack-test (0.6.2)
       Using actionpack (4.0.0)
       Using mime-types (1.23)
       Using polyglot (0.3.3)
       Using treetop (1.4.14)
       Using mail (2.5.4)
       Using actionmailer (4.0.0)
       Using activemodel (4.0.0)
       Using activerecord-deprecated_finders (1.0.3)
       Using arel (4.0.0)
       Using activerecord (4.0.0)
       Using bundler (1.3.2)
       Using chunky_png (1.2.8)
       Using coffee-script-source (1.6.3)
       Using execjs (1.4.0)
       Using coffee-script (2.2.0)
       Using thor (0.18.1)
       Using railties (4.0.0)
       Using coffee-rails (4.0.0)
       Using fssm (0.2.10)
       Using sass (3.2.9)
       Using compass (0.12.2)
       Using compass-rails (1.0.3) from git://github.com/milgner/compass-rails.g
it (at 1749c06)
       Using hike (1.2.3)
       Using jbuilder (1.4.2)
       Using jquery-rails (3.0.4)
       Using json (1.8.0)
       Using modernizr-rails (2.6.2.3)
       Using pg (0.15.1)
       Using tilt (1.4.1)
       Using sprockets (2.10.0)
       Using sprockets-rails (2.0.0)
       Using rails (4.0.0)
       Using rails_serve_static_assets (0.0.1)
       Using rails_stdout_logging (0.0.1)
       Using rails_12factor (0.0.2)
       Using rdoc (3.12.2)
       Using sass-rails (4.0.0)
       Using sdoc (0.3.20)
       Using turbolinks (1.3.0)
       Using uglifier (2.1.2)
       Using zurb-foundation (4.0.9)
       Your bundle is complete! It was installed into ./vendor/bundle
       Cleaning up the bundler cache.
       Removing rails_log_stdout (01b5bcc572e3)
       Removing rails3_serve_static_assets (84910ceb4ca2)
-----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       Asset precompilation completed (13.42s)
       Cleaning assets
-----> WARNINGS:
       Removing `Gemfile.lock` because it was generated on Windows.
       Bundler will do a full resolve so native gems are handled properly.
       This may result in unexpected gem versions being used in your app.
-----> Discovering process types
       Procfile declares types      -> (none)
       Default types for Ruby/Rails -> console, rake, web, worker

-----> Compiled slug size: 37.0MB
-----> Launching... done, v16
       http://myproject.herokuapp.com deployed to Heroku

To git@heroku.com:myproject.git
   82f4d58..e930ff1  master -> master

In your production config file, have you also tried setting: 在生产配置文件中,您是否还尝试过设置:

config.assets.compile = true
config.assets.digest = true

The config.assets.initialize_on_precompile line has been removed and is not needed in Rails 4. config.assets.initialize_on_precompile行已删除,在Rails 4中不需要。

Also, the rails_12factor gem is set up to include the two other gems you need for heroku, so you don't have to include them in your Gemfile. 另外,将rails_12factor gem设置为包括heroku所需的其他两个gem,因此您不必将它们包括在Gemfile中。 You can get more info about that on their github page. 您可以在其github页面上获取有关此信息的更多信息。

For whatever reason, though, I always had to make sure to use the rails image_tag to get my images to display in production. 但是,无论出于何种原因,我总是必须确保使用rails image_tag使我的图像在生产中显示。 Not sure if you are doing that, but it made a big difference on my app. 不知道您是否正在这样做,但这对我的应用程序产生了很大的影响。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM