Problem with Chartkick in a Rails Application

0

I'm trying to implement the Gem Chartkick in a Rails application, but I'm having a little problem.

My application has a relationship between two models:

class Animal < ActiveRecord::Base
  belongs_to :race
end

In my view, I'm trying to present the Percentage of Animals per Race.

<%= pie_chart  @animals.group(:race).count %>

The charts are being presented as follows:

How do I display the race names and not Race: 0x007f6d48812970 ?

    
asked by anonymous 09.12.2014 / 22:49

2 answers

0

You need to JOIN before invoking Chartkick:

<%= pie_chart  @animals.joins(:race).group('races.name').count %>

Note: I did not test the above code.

Source: link

    
10.12.2014 / 12:26
0

In the model add the method to_s

    def to_s
      "#{self.name}"
    end
    
07.03.2016 / 14:04