Ruby IF或Statement无效

时间:2015-07-03 18:59:06

标签: ruby ruby-on-rails-4

我在使用简单的IF语句时遇到问题。我尝试了几件事并没有成功。

   <% if item.ITEM.strip != 'OEM-LABELS' || item.ITEM.strip != 'DISCOUNT' || item.ITEM.strip != 'OEM-DVR' %>

   <% if item.ITEM.strip != 'OEM-LABELS' or item.ITEM.strip != 'DISCOUNT' or item.ITEM.strip != 'OEM-DVR' %>

2 个答案:

答案 0 :(得分:0)

如果我是你,我会简化如下

item = "A"
["C","B","A"].include?item #=> true
["C","B","D"].include?item #=> false


if ["C","B","D"].include?item
   do something

if !["C","B","D"].include?item  
   do something

答案 1 :(得分:0)

嘿,所以很少(不用看你的代码)

  1. 为此逻辑

    创建一个帮助器
    def needs_discounting(item)
      LOGIC HERE
    end
    
  2. 然后在你看来

      <% if needs_discounting(item.ITEM) %>
          STUFF
      <% end %>