Sf-60-Ruby-Cisco / BE-Ruby-Project

0 stars 0 forks source link

Display user's monthly statistics #40

Closed apoltieva closed 1 year ago

apoltieva commented 2 years ago

As a user, I want to see how much I spend on my car monthly. Steps:

Note: you may use some visual gem like chartkick https://www.youtube.com/watch?v=X_nvVZvhJFk or you can just output the results

Stoyan83 commented 2 years ago

Hello when I render chart table with chartkick gem since we are using money-rails gem which make columns in db in integers when I display chart table the amount of money is shown in cents. for example 10000 instead $100. I read a lot on that issue and I think chartkick can't format values out of the box. Is there any known way I can use to format integers into money shown in the chart table that is rendered from chartkick?

Stoyan83 commented 2 years ago

I find answer of mine question: chartkick gem and his charts takes as argument associative array with key value pair. So you can change the value and format it as you want and then give back the hole dictionary as argument to chartckick. In slim view something like:

- @total_repairs.each do |key, value| == bar_chart ({key => value/100.to_f})

And in controller:

@total_repairs = current_user.cars.joins(:repairs).group_by_month(:date, format: "%B %Y").sum(:amount_cents)