Ruby / Sinatra / erb:404用于加载图像

时间:2013-11-02 10:55:04

标签: ruby image sinatra erb

我尝试显示图像,但日志中的响应代码为404:

0:0:0:0:0:0:0:1 - - [02/Nov/2013 11:23:55] "GET /public/images/gtk_refresh.png HTTP/1.1" 404 466 0.0030
0:0:0:0:0:0:0:1 - - [02/Nov/2013:11:23:55 MEZ] "GET /public/images/gtk_refresh.png HTTP/1.1" 404 466
http://localhost:4567/main-> /public/images/gtk_refresh.png

rb文件:

get '/main' do
  erb: main         
end

erb文件:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1

/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>hello world</title>
</head>

<body>    
    <img src="public/images/gtk_refresh.png" />     
</body>
</html>

我尝试了图像的相对和绝对路径,它不起作用。

2 个答案:

答案 0 :(得分:5)

变化:

<img src="public/images/gtk_refresh.png" />

为:

<img src="/images/gtk_refresh.png" />  

答案 1 :(得分:0)

您也可以使用网址助手。

<img src="<%= url('/images/gtk_refresh.png') %>" />