I have a rails 3 project where boards has_many topics. I'm trying to add a banner image by rendering a header partial:
<!DOCTYPE html>
<html>
<head>
<title>Forum</title>
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
</head>
<body>
<%= render :partial => "layouts/header" %>
<%= yield %>
</body>
</html>
And here's my header:
<div id="top">
<img src = '../public/images/cspill_banner.gif' style="height: 300px"/>
<div>
But when I go to this link http://localhost:3000/boards/1/topics/1 for some reason my image link is broken. When I follow the url I see that Rails is trying to access boards/1/images instead of /public/开发者_如何学JAVAimages:
Routing Error
No route matches "/boards/1/images/cspill_banner.gif"
Why is this? How can I fix it?
Use the Rails image_tag
helper:
For example:
<%= image_tag 'cspill_banner.gif', :style => 'height:300px' />
精彩评论