ruby-on-rails - html.erb Rails 中的 if 条件

标签 ruby-on-rails ruby

如何在 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>

最佳答案

如果您有权访问@time并且状态是它的一个属性,其值可以是“待定”(您没有在问题中添加的内容),那么您可以执行以下操作:

<% 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 %>

关于ruby-on-rails - html.erb Rails 中的 if 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46703209/

相关文章:

python - 如何在 ruby​​ 中进行图像处理? Ruby 中没有 OpenCv?

mysql - 将信息发送到 Dashing 中的小部件

ruby-on-rails - Rails - 在 image_tag 中插入变量

ruby-on-rails - 永久修复尾部 : cannot watch `log/development.log' : No space left on device

mysql - Rails 数据库查询

ruby-on-rails - 在 Rails 3 中禁用 BLOB 日志记录

ruby-on-rails - 在 webrick 服务器的生产模式下运行 rails

ruby-on-rails - Ruby GIS - 将 NAD83 转换为 WGS84

ruby - 如何在 Ruby 中检测字符串中的某些 Unicode 字符?

ruby - 使用 Ruby 将一个数组插入另一个数组,并返回方括号