在 Rails 中找不到图像的路径 [英] No Route Found for Images in Rails

查看:49
本文介绍了在 Rails 中找不到图像的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点困惑,我正在通过 css 显示图像,它工作正常.但是当我使用视图显示图像时,它不会显示.以下是我正在使用的简单代码.但我找不到哪里出了问题!

I am little bit confuse that I am showing images through css it's working fine. But when I am showing images using views it's not display. Following is simple code I am using. But I cannot find what's wrong!

new.html.erb

new.html.erb

<h1>Users#new</h1>
<p>Find me in app/views/users/new.html.erb</p>
<img src='close.png'>

我在控制台中收到此错误:

I am getting this error in console:

ActionController::RoutingError (No route matches [GET] "/users/close.png"):
  actionpack (3.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.3) lib/rails/rack/logger.rb:26:in `call_app'
  railties (3.2.3) lib/rails/rack/logger.rb:16:in `call'

这是项目的目录图像:

推荐答案

使用 image_tag 辅助方法 - 只要您将图像存储在资产管道的位置,它就会自动为您放入正确的 src 路径期望他们是(你是).例如

It would be easier to use the image_tag helper method - this will put in the right src path for you automatically, so long as you are storing your images where the asset pipeline expects them to be (you are). e.g.

<%= image_tag 'close.png' %>

这篇关于在 Rails 中找不到图像的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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