-1

What I'm trying to do is print Pending Quotes if the count is 0 or >1 and Pending Quote if the count ==1 but if the count is >1, the output is 2 true, the other two cases work fine though and I can't see anything obvious.

<%= @pending.nil? ? '0' : @pending.count %>
<%= (!@pending.nil? and @pending.count > 1) or (!@pending.nil? and @pending.count == 0) ? 'Pending Quotes' : 'Pending Quote' %>
4

3 回答 3

5

我会使用pluralize助手:

<%= pluralize(@pending, 'Pending Quote') %>
于 2013-10-03T08:18:59.253 回答
1

在德摩根的帮助下...

@pending.try(:count) == 1 ? 'Pending Quote' : 'Pending Quotes'
于 2013-10-03T09:23:40.183 回答
1

你必须这样写:

((!@pending.nil? and @pending.count > 1) or (!@pending.nil? and @pending.count == 0)) ? 'Pending Quotes' : 'Pending Quote'

你也可以写成

(!@pending.nil? && (@pending.count > 1 || @pending.count == 0)) ? 'Pending Quotes' : 'Pending Quote'
于 2013-10-03T08:12:35.200 回答