0
I’m developing an application on Ails, but I ran into a problem that may be simple, but it’s killing me inside. I have an indicator on a screen that shows the number of credits that the selected coach has, and the number of coachees associated with the selected coach. In the coachs controller, in part Edit, I search for this information in the database as follows:
To find the amount of coachees associated:
@total_coachees = @current_account.coachees
.where(coach_id: params[:id])
@act_coaches = (@total_coachees.activated.select(:id).count)
Getting the right result, and printing in the view with a simple @act_coachees
, where the view displays only the desired number, 3
To get the amount of credits:
@total_cents = @current_account.coaches
.where(id: params[:id])
@total = (@total_cents.select(:credits_available).to_a)
Printing in view as above, using @total
However, the results are inconsistent, using .to_a at the end of the query, Rails prints in the view the following result:
[#<Coach id: nil, credits_available: 200>]
Changing to to_json, get:
[{"id":null,"credits_available":200}]
And by not putting any shape at the end, I get:
#<Coach::ActiveRecord_AssociationRelation:0x00007f7a341dbe50>
These results printed on the screen, the way they are presented here.
What am I doing wrong?