2013-10-03 2 views
-1

카운트가 0 또는 >1Pending Quote 개수 ==1 경우이지만 count>1 경우, 출력이 다른 두 경우가 있지만 잘 작동하고, 2 true 경우 난 할 노력하고있어 인쇄 Pending Quotes입니다 나는 명백한 것을 볼 수 없다.루비 삼항 만약 버그

<%= @pending.nil? ? '0' : @pending.count %> 
<%= ([email protected]? and @pending.count > 1) or ([email protected]? and @pending.count == 0) ? 'Pending Quotes' : 'Pending Quote' %> 

답변

1

당신은 이런 식으로 작성해야합니다 :

(([email protected]? and @pending.count > 1) or ([email protected]? and @pending.count == 0)) ? 'Pending Quotes' : 'Pending Quote' 

또한

([email protected]? && (@pending.count > 1 || @pending.count == 0)) ? 'Pending Quotes' : 'Pending Quote' 
+0

아, 지금 어리 석다. 고마워요. SO가 나를 허용 할 때 받아 들일 것입니다. – martincarlin87

+2

참고 : 루비에서는 부울 표현에'&&''||'를 사용하는 관용적 인 표현입니다. 흐름 제어에는'및'을 사용하십시오. 또한 OP에 "! x.nil?" 보통 단순히 "x"로 더 좋습니다. – tokland

+0

@tokland 나는 당신과 동의한다 –

5

로 쓸 수 나는 pluralize 도우미 사용하십시오 :

<%= pluralize(@pending, 'Pending Quote') %> 
+0

나는 ROR의 조금을 모른다. .. 그래서 나는 단지 루비에 달라 붙었다. .. :) –

1

로를 De Morgan의 도움 ...

@pending.try(:count) == 1 ? 'Pending Quote' : 'Pending Quotes' 
+0

감사합니다, 그것은 그것을 넣는 매우 청초한 길이다 – martincarlin87