有些问题acessing在生产模式下资产文件 [英] Some issues acessing asset files in production mode

查看:213
本文介绍了有些问题acessing在生产模式下资产文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我on Rails的4.1.1和我的本地机器上使用Ruby我有以下图片:

I am using Ruby on Rails 4.1.1 and on my local machine I have the following image:

# Directory: MyApp/app/assets/images/
logo.png

我上传MyApp的使用Capistrano的创业板和一切似乎都如预期工作。然而,当我尝试以下网址通过浏览器来访问我的网站

I upload MyApp using the Capistrano gem and all seems to work as expected. However when I try to access my website through the browser at the following URLs

1) http://www.myapp.org/logo.png
2) http://www.myapp.org/assets/logo.png
3) http://www.myapp.org/images/logo.png
4) http://www.myapp.org/assets/images/logo.png

然后我得到一个错误页面:

then I get an error page:

The page you were looking for doesn't exist.
You may have mistyped the address or the page may have moved.

在日志文件中我得到:

1) ActionController::RoutingError (No route matches [GET] "/logo.png"):
2) ActionController::RoutingError (No route matches [GET] "/assets/logo.png"):
3) ActionController::RoutingError (No route matches [GET] "/images/logo.png"):
4) ActionController::RoutingError (No route matches [GET] "/assets/images/logo.png"):

  actionpack (4.1.1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.1.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.1.1) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.1.1) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.1.1) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.1.1) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.1.1) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.1.1) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.1.1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.1.1) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
  rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
  railties (4.1.1) lib/rails/engine.rb:514:in `call'
  railties (4.1.1) lib/rails/application.rb:144:in `call'
  railties (4.1.1) lib/rails/railtie.rb:194:in `public_send'
  railties (4.1.1) lib/rails/railtie.rb:194:in `method_missing'
  /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.45/lib/phusion_passenger/rack/thread_handler_extension.rb:74:in `process_request'
  /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.45/lib/phusion_passenger/request_handler/thread_handler.rb:141:in `accept_and_process_next_request'
  /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.45/lib/phusion_passenger/request_handler/thread_handler.rb:109:in `main_loop'
  /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.45/lib/phusion_passenger/request_handler.rb:448:in `block (3 levels) in start_threads'

这是什么问题,我该怎么解决呢?

What is the problem and how can I solve it?


  • 在我的本地机器(开发模式),我没有问题。

  • 我的远程机器运行的Ubuntu LTS 12.04,Phusion的乘客4.0.45,
    阿帕奇2.2.22。

推荐答案

这是在生产的所有编制资产都附加到文件名的指纹ID。因此,在生产,logo.png在技术上不存在了。现在什么应该存在为标志,SOME_FINGERPRINT_ID.png。在这里看到更多的信息:

All assets that are compiled in Production have a fingerprint ID appended to the file name. Therefore, in production, logo.png does not technically exist anymore. What should exist now is logo-SOME_FINGERPRINT_ID.png. See more info here:

<一个href=\"http://guides.rubyonrails.org/asset_pipeline.html#what-is-fingerprinting-and-why-should-i-care-questionmark\" rel=\"nofollow\">http://guides.rubyonrails.org/asset_pipeline.html#what-is-fingerprinting-and-why-should-i-care-questionmark

另外,如果你希望服务仅仅是静态图片,你需要把它在公用文件夹dir的图像。那么你需要告诉Apache或Nginx的从该位置提供静态资产。

Also, if you wish to serve just the static image, you will need to put it in the images dir of the public folder. You will then need to tell Apache or Nginx to serve static assets from that location.

编辑:要链接到的图像在资产管道 -

To link to an image in your Asset Pipeline -

link_to(LINK_TEXT_OR_IMAGE_TAG_HELPER, image_path(IMAGE_NAME))

资源网址助手

这篇关于有些问题acessing在生产模式下资产文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆