Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在Rails的ERB中实现if/not最干净的方法是什么?_Ruby On Rails_Ruby On Rails 3_Views_Erb - Fatal编程技术网

Ruby on rails 在Rails的ERB中实现if/not最干净的方法是什么?

Ruby on rails 在Rails的ERB中实现if/not最干净的方法是什么?,ruby-on-rails,ruby-on-rails-3,views,erb,Ruby On Rails,Ruby On Rails 3,Views,Erb,从索引视图中考虑以下代码: <td> <%= 'foo' if bar == BAZ %> <%= 'qux' if bar != BAZ %> </td> 这是最干净的方法,还是有更好的方法?这似乎是一个很好的例子: 除此之外,一个普通的旧if/else: <%= if bar == BAZ then 'foo' else 'qux' end %> <%= if bar == BAZ th

从索引视图中考虑以下代码:

<td>
  <%= 'foo' if bar == BAZ %>
  <%= 'qux' if bar != BAZ %>
</td>


这是最干净的方法,还是有更好的方法?

这似乎是一个很好的例子:


除此之外,一个普通的旧if/else:

<%= if bar == BAZ then 'foo'
    else 'qux'
    end
%>

<%= if bar == BAZ then 'foo'
    else 'qux'
    end
%>