samedi 12 septembre 2015

conditions on methods rails 4

Relations:

vote.rb

belongs_to :user
belongs_to :celebrity, counter_cache: true

celebrity.rb

belongs_to :user
belongs_to :category
has_many :votes

def total_downvotes         
Vote.where('vote_devote = ?', false).count
end

this will work, but I need to look for celebrity_id as well that is something like Vote.where('celebrity_id=?',@celebrities.id, 'vote_devote = ?', false) in my celebrity model

Can anyone help me here

Aucun commentaire:

Enregistrer un commentaire