如何在 Ruby on Rails 中使用 && in if ?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2935710/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I use && in if in Ruby on Rails?
提问by Timothy T.
I tried the following && conditional for my if statement and I get a "bad range" error:
我为 if 语句尝试了以下 && 条件,但出现“错误范围”错误:
<% if (from_today(contact, call.days) == 0..7) && (show_status(contact, call) == 'no status') %>
Why and how can I fix it? The only other way I could do it was to have a second nested if statement and break it apart...not pretty :(
为什么以及如何修复它?我能做到的唯一另一种方法是使用第二个嵌套的 if 语句并将其分解...不漂亮:(
回答by Dolph
<% if (from_today(contact, call.days) == (0..7) && show_status(contact, call) == 'no status') %>
回答by x1a4
Try putting the 0..7in parentheses. The &&is not your problem here.
尝试将 放在0..7括号中。这&&不是你的问题。

