我正在使用Ruby on Rails 4.1.1,在我的本地机器上,我有以下图像:
# Directory: MyApp/app/assets/images/
logo.png
我使用Capistrano宝石上传MyApp,所有内容似乎都按预期工作。但是,当我尝试通过以下网址的浏览器访问我的网站时
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
然后我收到一个错误页面:
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'
问题是什么,如何解决?
答案 0 :(得分:0)
在Production中编译的所有资产都有一个附加到文件名的指纹ID。因此,在生产中,logo.png在技术上不再存在。现在应该存在的是logo-SOME_FINGERPRINT_ID.png。在这里查看更多信息:
此外,如果您只想提供静态图像,则需要将其放在公用文件夹的图像目录中。然后,您需要告诉Apache或Nginx从该位置提供静态资产。
编辑:链接到资产管道中的图像 -
link_to(LINK_TEXT_OR_IMAGE_TAG_HELPER, image_path(IMAGE_NAME))