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
嗨,我添加了我的視圖中的代碼。如果你需要其他東西,請告訴我。 –