Oops. My bad. do this instead:  
try(:reviews).average(:rating).round(1)


Albert


On Wednesday, April 9, 2014 at 12:35 PM, crokobit wrote:

> In app/models/video.rb:
> > + #video should not have many category in this project; however, I am lazy to fix this... > + validates_presence_of :title, :description > + > + has_many :reviews > + > + def self.search_by_title(search_term) > + return [] if search_term.blank? > + where("title LIKE ?", "%#{search_term}%").order("created_at DESC") > + end > + > + def number_of_reviews > + reviews.count > + end > + > + def averge_rating > + rating_data = self.reviews.map{ |i| i.rating }  
> reviews.average.try(:rating).round(1) does not work. However, reviews.average(:rating).round(1) work. ?
>  
> —
> Reply to this email directly or view it on GitHub (https://github.com/crokobit/myflix/pull/1/files#r11433047).
>  
>  
>