2017-06-20 42 views
-4

使用or操作符時,My Ruby if語句失敗。爲什麼IF語句在OR ||時失敗用來?

<% if @body_id == 'plants' || 'trees' %> 
    <meta name="robots" content="noindex, nofollow"> 
<% end %> 
+0

你是什麼意思與「失敗」,你會得到一個錯誤?如果是,請包括堆棧跟蹤。如果這是意外行爲,請添加您的實際和預期行爲。 – DarkCygnus

回答

3

你不能使用||那樣,ID做['plants', 'trees'].includes? @body_id代替。

+1

'%w [植物樹]'所有冰雹rubocop –

+0

@dezman - 謝謝! – traci123me

1

不是嗎?

<% if @body_id == 'plants' || @body_id == 'trees' %>