1

我尝试从子域的名称中获取架构的大小。公共架构中的子域名称,

在控制器.rb

@account = Account.find_by_subdomain(params[:subdomain])
@itemlist = Account.find(:all,:select => 'subdomain')
@schemasize = ActiveRecord::Base.connection.select_rows(%q{select pg_size_pretty(CAST((SELECT SUM(pg_total_relation_size(table_schema || '.' || table_name) ) FROM information_schema.tables WHERE table_schema = '}+@itemlist.to_s+%q{') As bigint) )  As schema_size}).to_s.gsub(/\D/, '').to_i

获取 localhost:3000/namesubdomain

命令提示符下的输出

 (21.0ms)  select pg_size_pretty(CAST((SELECT SUM(pg_total_relation_size(table
_schema || '.' || table_name) ) FROM information_schema.tables WHERE table_schem
a = '[#<Account subdomain: "namesubdomain">]') As bigint) ) As schema_size

我想在命令提示符下输出,例如

   (151.0ms)  select pg_size_pretty(CAST((SELECT SUM(pg_total_relation_size(tabl
e_schema || '.' || table_name) ) FROM information_schema.tables WHERE table_sche
ma = 'namesubdomain') As bigint) ) As schema_size

任何的想法?

4

1 回答 1

1

@itemlist.to_s将对象呈现为字符串。由于对象实际上是一个数组,因此呈现为字符串只会输出有关数组的信息而不是内容。您可能想要的是:

@itemlist.first.subdomain

或者:

@itemlist.map(&:subdomain).join(" ")
于 2012-11-27T19:31:05.023 回答