1
私はRoRアプリケーションでChartkickを使用していて、Group
にあるPeople
のすべてを表示する円グラフを作成しようとしています。私のグループと個人モデルは両方ともHABTMです。アクティブなレコードを使って各グループの人数を把握する方法を知っていれば、チャートは現在動作しており、グループ数(スクリーンショットとコードは下記)のみ表示しています。ここ アクティブレコード - グループ内の人数をグラフ化していますか?
<%= pie_chart Group.group(:name).count %>
ある
はここに私のスキーマ
create_table "people", force: :cascade do |t|
t.string "phone_number"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "subscribed", default: true, null: false
t.string "city"
t.string "state"
t.string "zip"
t.string "country"
end
create_table "groups", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "groups_people", id: false, force: :cascade do |t|
t.integer "group_id", null: false
t.integer "person_id", null: false
end
あるスクリーンショットに人物モデル
されています10class Person < ActiveRecord::Base
has_many :deliveries
has_and_belongs_to_many :groups
ここでは、グループモデルところで
class Group < ActiveRecord::Base
has_and_belongs_to_many :people
has_and_belongs_to_many :messages
end
私はあなたが正しい軌道に乗っていると思うが、このエラーが発生する – Bitwise
SQLite3 :: SQLException: "グループ"の近く:構文エラー:SELECT COUNT(*)AS count_all、グループASグループfrom "people" GROUP BY "group " – Bitwise
あなたの質問をモデルとスキーマコードでお知らせください) – Ilya