-2

I'm looking for a Ruby on Rails view helper which:

For example:

2.0.0p247 :001 > ["Audit", "Porsche", "Peugeot"].to_sentence("car", limit: 3)
 => "Audit, Porsche, and Peugeot"
2.0.0p247 :002 > ["Audit", "Porsche", "Peugeot", "Mitsubishi"].to_sentence("car", limit: 3)
 => "4 cars"

If this kind of helper doesn't exists I can create it but I would avoid to duplicate something existing.

ZedTuX
  • 2,859
  • 3
  • 28
  • 58

3 Answers3

0

you don't need a helper. You can just use a conditional in the view:

<% if array.length < min %>
  <% array.to_sentence(...) %>
<% elsif array.length > max %>
  <%= array.length %><%= string.pluralize %>
<% end %>
La-comadreja
  • 5,627
  • 11
  • 36
  • 64
  • Well, thank you very much for this quick answer, but the question is (yes or no) there is a Rails helper which do what I have described :) – ZedTuX Dec 05 '13 at 20:09
0

This is a little shorter version

<% a = ["Audit", "Porsche", "Peugeot"] %>
<%= a.size < 4 ? a.to_sentence : a.size.to_s + " cars" %>
beck03076
  • 3,268
  • 2
  • 27
  • 37
0

Since the OP has asked for a one word answer, however useless that is, the answer is:

No.

Gareth
  • 133,157
  • 36
  • 148
  • 157