ruby - Showing near "total_entries" in Rails -
using ror 2.3.8
usually have following code:
showing <%= @shops.total_entries %> shops in canada. yields result:
showing 46 shops in canada what if want show round-down value:
showing 40+ shops in canada whereas <10 total entries, should show exact number.
thankyou.
def round(total) total > 10 && total%10 != 0 ? [total/10*10,"+"].join : total.to_s end showing <%= round(@shops.total_entries) %> shops in canada. and of course better wrap model method
class shop < activerecord::base def self.round total = count total > 10 && total%10 != 0 ? [total/10*10,"+"].join : total.to_s # instead of using `[total/10*10,"+"].join` can use `(total/10*10).to_s+"+"` end end @shops = shop.were(:region => "canada") showing <%= @shops.round %> shops in canada.
Comments
Post a Comment