1

サブドメインの名前からスキーマのサイズを取得しようとしています..スキーマパブリックのサブドメインの名前、

controller.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 に答える