我是 Rails 的新手,我需要执行一些 sql 查询并将其数组输出到视图。
在控制器上
@accounts = Account.all
@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.map(&:subdomain).join(" ")+%q{') As bigint) ) As schema_size}).to_s.gsub(/\D/, '').to_f / 1024
命令输出
Account Load (36.0ms) SELECT "public"."accounts".* FROM "public"."accounts"
Account Load (2.0ms) SELECT subdomain FROM "public"."accounts"
(88.0ms) select pg_size_pretty(CAST((SELECT SUM(pg_total_relation_size(table
_schema || '.' || table_name) ) FROM information_schema.tables WHERE table_schem
a = 'subdomain1 subdomain2') As bigint) ) As schema_size
Rendered accounts/kapasitas.html.erb within layouts/admin (239.0ms)
Completed 200 OK in 2765ms (Views: 2208.1ms | ActiveRecord: 484.0ms)
在 html.erb 上
<tr>
<td><%= account.subdomain %></td>
<td><%= @schemasize %></td>
</tr>
视图输出:http: //i.cubeupload.com/jVrShN.png
不能每个子域的大小模式。
我想要输出,例如:http: //i.cubeupload.com/PMPBYn.png
我怎样才能做到这一点?任何的想法?