1
我对Ruby on Rails还是比较新的。我用Ruby image_tag替换了一个图像域。当我尝试使用CSS调整图像大小时,我注意到图像下面有额外的空白空间......检查完元素后,我看到同一图像有两个标签,我不知道为什么。有没有其他人看到过这种情况?Ruby on Rails image_tag将两个<img>标签放在我的HTML中
这里是我把我的代码:
<%= image_tag (post.image_url), id: "post-image", class: "img-responsive" %>
这里是我所看到的,当我检查图像元素:
<img id="post-image" class="img-responsive" src="http://www.mypigeonforge.com/uploadedImages/Business/215LodgeCabin(1).jpg" alt="215lodgecabin(1)">
<img id="post-image" class="img-responsive" src="">
我不知道为什么会这样..任何帮助都会很棒。另外,如果我以任何方式模糊,我表示歉意。这是我的第一个问题。
谢谢!
编辑:这是我使用的代码:
index.html.erb
<p id="notice"><%= notice %></p>
<h1>Posts</h1>
<table>
<thead>
<tr>
<th>Title</th>
<th>Content</th>
<th>Posted</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<div class="container">
<div class="row">
<% @posts.each do |post| %>
<%= render partial: 'post', locals: { post: post } %>
<% end %>
</div>
</div>
</tbody>
</table>
<br>
<%= link_to 'New Post', new_post_path %>
_post.html.erb
<% cache post do %>
<div class="col-md-4 col-sm-6 col-xs-12">
<%= link_to image_tag(post.image_url, id: "post-image", class: "img-responsive") %>
<p><%= post.title %></p>
<p><%= post.content %></p>
<p><%= post.posted %></p>
<%= link_to 'Show', post %>
<%= link_to 'Edit', edit_post_path(post) %>
<%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %>
</div>
<% end %>
您可以添加视图的整个代码吗? –
确保它不在双循环中。此外,将代码粘贴到范围... – 7urkm3n
嗨,我添加了我的视图中的代码。如果你需要其他东西,请告诉我。 –