开发者

Nested urls in Rails causes images routing problem

开发者 https://www.devze.com 2023-03-24 20:05 出处:网络
I have a rails 3 project where boards has_many topics. I\'m trying to add a banner image by rendering a header partial:

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' />
0

精彩评论

暂无评论...
验证码 换一张
取 消