我的图像存储在/rubyprograms/search/public/urlimages
中。我通过终端检查以确保路径在其中并且所有图像都在其中。我链接到图像,例如,在以下路径:/rubyprograms/search/public/urlimages/2173513720.jpg
,但是我的应用程序似乎找不到图像。例如,这是我的日志中的错误:
Started GET "/rubyprograms/search/public/urlimages/2173486240.jpg" for 127.0.0.1 at Thu Jul 07 21:34:23 -0700 2011
ActionController::RoutingError (No route matches "/rubyprograms/search/public/urlimages/2173486240.jpg"):
但是我知道图像在那条路线上。为什么会这样呢?
最佳答案
如果您的应用程序位于/rubyprograms/search
中,那么public/
目录将用作所有非Rails请求的根目录。
因此,图像的正确路径将是/urlimages/2173486240.jpg
。
Rails提供了一个方便的图像助手image_tag
,它实际上为您创建了图像标签。用法是:
<%= image_tag('2173486240.jpg') %>
# will create <img src="/images/2173486240.jpg" alt="" />
请注意,这将创建整个html标签,并假设您的图片包含在
public/images/
中。
关于ruby-on-rails - 我的应用找不到我的图片路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6619088/