2015-07-03 50 views
-1

我遇到了简单的IF语句问题。我曾尝试过几件事情,但没有成功。红宝石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' %> 

回答

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 
0

嘿那么几件事情(不看更多的代码的)

  1. 为此逻辑创建一个帮手

    def needs_discounting(item) 
        LOGIC HERE 
    end 
    
在你看来

然后

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