-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' %>
martincarlin87
  • 10,848
  • 24
  • 98
  • 145

3 Answers3

5

I'd use the pluralize helper:

<%= pluralize(@pending, 'Pending Quote') %>
Stefan
  • 109,145
  • 14
  • 143
  • 218
1

You have to write this way :

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

You could also write it as

(!@pending.nil? && (@pending.count > 1 || @pending.count == 0)) ? 'Pending Quotes' : 'Pending Quote'
Arup Rakshit
  • 116,827
  • 30
  • 260
  • 317
1

With the help of De Morgan...

@pending.try(:count) == 1 ? 'Pending Quote' : 'Pending Quotes'
spickermann
  • 100,941
  • 9
  • 101
  • 131