ruby on rails - Return all hashes based on user id as key -
i got array hashes. inside hashes has unique user id. need return of user's likes:
p = post.first all_likes = p.likes # returns: [0][1][2] etc # inside hash looks like: [0] #<like:0x007f81d3dfb310> { id: => 4, user_id: => 1, like_sent: => 1 # 1 }
let's assume all_likes
has many users , need user_id: 1
's total like_sent
. how that?
all_likes.find {|f| f["user_id"] = current_user.id } # returns 1 hash. need return if more found.
so if "jason" likes post 10 times, need grab total likes. how return matching hashes. that's perfect question.
try
all_likes.where 'user_id = ?', current_user.id
and find
method has different syntax, this:
all_likes.find :all, :conditions => ['user_id = ?', current_user.id]
look docs
Comments
Post a Comment