Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 显示“接近”;“U项目总数”;在轨_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails 显示“接近”;“U项目总数”;在轨

Ruby on rails 显示“接近”;“U项目总数”;在轨,ruby-on-rails,ruby,Ruby On Rails,Ruby,使用RoR 2.3.8 通常我们有以下代码: Showing <%= @shops.total_entries %> shops in Canada. 如果我想让它显示舍入值,该怎么办: Showing 40+ shops in Canada 而对于def轮(总计) 总计>10&&总计%10!=0 ? [total/10*10,“+”]。加入:total.to_ 结束 展示加拿大的商店。 当然,最好将其包装为一个模型方法 class Shop < ActiveRecord

使用RoR 2.3.8

通常我们有以下代码:

Showing <%= @shops.total_entries %> shops in Canada.
如果我想让它显示舍入值,该怎么办:

Showing 40+ shops in Canada
而对于
def轮(总计)
总计>10&&总计%10!=0 ? [total/10*10,“+”]。加入:total.to_
结束
展示加拿大的商店。
当然,最好将其包装为一个模型方法

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` you can use `(total/10*10).to_s+"+"`
  end
end

@shops = Shop.were(:region => "Canada")

Showing <%= @shops.round %> shops in Canada.
class-Shop10&&总计%10!=0 ? [total/10*10,“+”]。加入:total.to_
#不要使用“[total/10*10,”+”]。加入“你可以使用”(total/10*10)。加入“+”`
结束
结束
@商店=商店。是(:地区=>“加拿大”)
展示加拿大的商店。
def round(total)
  total > 10 && total%10 != 0 ? [total/10*10,"+"].join : total.to_s
end

Showing <%= round(@shops.total_entries) %> shops in Canada.
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` you can use `(total/10*10).to_s+"+"`
  end
end

@shops = Shop.were(:region => "Canada")

Showing <%= @shops.round %> shops in Canada.