mercredi 2 septembre 2015

append data to an array rails 4

I need to append data to a variable

@celebrity = Celebrity.includes(:category).where('category_id = ?', params[:id])
test =[]
@celebrity.each do |celeb|
  @vote = Vote.where('celebrity_id = ?', celeb).count
  test  << {vote_count:@vote}
end

when i debug 'test',

abort test.inspect

I am getting the result of

[{:vote_count=>2}, {:vote_count=>1}, {:vote_count=>0}]

but, my question is how can I append vote_count to @celebrity , can anyone please help me out

Aucun commentaire:

Enregistrer un commentaire