如何在HTML中放置if条件,以伪代码形式,我想实现以下目标:
if @time.status is pending
place edit and delete below the message
else
not just display
end
这是我目前的代码:
<% @value.each do |s| %>
<p><strong>Message:</strong>
<%= s.message %>
</p>
<p><strong>Date</strong>
<%= s.date %>
</p>
<p><strong>Status:</strong>
<%= s.status %>
</p>
<p>
<%= link_to 'Edit', value(), %>
<%= link_to 'Delete', value(), %>
</p>
答案 0 :(得分:3)
如果您有权访问@time并且status是其属性,其值可以是“待定”(您未在问题中添加的内容),则可以执行以下操作:
<% if @time.status == 'pending' %>
<!-- place edit and delete -->
<% else %>
<% @value.each do |s| %>
<p>
<strong>Message:</strong>
<%= s.message %>
</p>
<p>
<strong>Date</strong>
<%= s.date %>
</p>
<p>
<strong>Status:</strong>
<%= s.status %>
</p>
<p>
<%= link_to 'Edit', value(), %>
<%= link_to 'Delete', value(), %>
</p>
<% end %>
<% end %>
答案 1 :(得分:1)
与迭代相同
<% if @time.status=="PENDING" %>
#your html code for edit in delete
<%end%>