Chartkick Problem in a Rails Application

Asked

Viewed 152 times

0

I’m trying to implement the Gem Chartkick in a Rails application, but I’m having a small 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 by Breed.

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

The Charts are being presented as follows:

inserir a descrição da imagem aqui

How do I present the names of the Races and not Race:0x007f6d48812970?

2 answers

0

In the model add the to_s method

    def to_s
      "#{self.name}"
    end

0


  • Thank you so much for the help! It worked perfectly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.