没有路线与Rails中的资产/图像匹配 [英] no route matches for assets/images in Rails

查看:71
本文介绍了没有路线与Rails中的资产/图像匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在导轨上工作,图像不可见并显示错误.

Working on rails, images are not visible and giving error.

Started GET "/assets/home.png" for 127.0.0.1 at 2012-06-19 12:23:24 +0530
Served asset /home.png - 404 Not Found (24ms)
ActionController::RoutingError (No route matches [GET] "/assets/home.png"):

我已经使用了命令

rake assets:precompile

production.rb

production.rb

config.assets.compress = true
config.assets.compile = false

application.rb

application.rb

config.assets.enabled = true
config.assets.version = '1.0'

感谢您的帮助!

推荐答案

实际上,您不能使用/assets/home.png路径引用图像. 它将在开发模式下工作,但在生产中,所有资产的文件名都带有指纹(请阅读

Actually you cannot reference your image with /assets/home.png path. It will work in development mode, but in production all of your assets have a fingerprint in their filename (read this http://guides.rubyonrails.org/asset_pipeline.html#what-is-fingerprinting-and-why-should-i-care-questionmark)

这就是为什么在启用资产管道的应用程序中,您需要使用辅助方法来引用所有资产的原因.阅读此文档以了解Ruby,JS和Sass文件中可用的不同帮助器:

That's why, in assets-pipeline enabled applications you need to reference all of your assets using helper methods. Read this doc to learn about the different helpers available in Ruby, JS and Sass files: http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets

这篇关于没有路线与Rails中的资产/图像匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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