I need to add '%' symbol in 'votes_count' field
My controller,
@celebrity = Celebrity.includes(:category).order(votes_count: :desc)
I am counting the total votes here
total_votes = Vote.count.to_f
changing the total no. of votes to percentage
@celebrity.each do |celeb|
celeb["votes_count"] = (celeb.votes_count / total_votes * 100).round(2)
end
here, I am changing into json
respond_to do |format|
format.json { render json: @celebrity.to_json(:include =>{:category => {:only => [:category]}})}
end
My output is [{"id":3,"name":"saravana","gender":false,"category_id":"1","votes_count":25}]
My question is how can I add '%' symbol in votes_count
Aucun commentaire:
Enregistrer un commentaire