我是一個新手,我需要執行一些sql查詢和數組輸出到視圖。Array of ActiveRecord :: Base.connection.execute Ruby on Rails
上命令
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)
conttroler
@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 = '}[email protected](&:subdomain).join(" ")+%q{') As bigint)) As schema_size}).to_s.gsub(/\D/, '').to_f/1024
輸出上html.erb上視圖
<tr>
<td><%= account.subdomain %></td>
<td><%= @schemasize %></td>
</tr>
輸出:http://i.cubeupload.com/jVrShN.png
不能爲每個子域的大小模式。
我想輸出,如:http://i.cubeupload.com/PMPBYn.png
我怎麼能這樣做? 有什麼想法?
thx bro,但這不是我的意思,我希望我的查詢把架構大小**每個子域** ..如何從我的查詢中獲取數組。 – GeekToL
@KapanjadiMomod:啊,我明白了。看看我更新的答案的底部。 –