In an app using the chartkick gem:
I have the following database table relations:
class User < ActiveRecord::Base
has_many :games
contains id, email
end
class Game < ActiveRecord::Base
has_many :levels
belongs_to :user
#contains id, user_id, name
accepts_nested_attributes_for :levels
end
class Level < ActiveRecord::Base
belongs_to :game
#contains id, score and game_id
end
How do i plot the score acquired by each player? And then the average score acquired by each player each game?
I want to do something like:
<%= column_chart Level.group(:user.email).sum(:score) %>
I managed to do:
<%= column_chart Level.group(:game_id).sum(:score) %>
The entire code can be found here