I am totally newbie in the rails and I have searched for my problem to solve it then I found an example from here. Comming to my problem I have two databases they are
one looks like as follows “Names” table
s.no name place satisfactionscore no. ofratings rank
1 raj usa 2 ravi usa
And I user_ratings table looks like
id user_id names_id R1 R2 R3 R4 R5
1 1 1 2 3 4
2 2 1 4 5
3 3 2 2 3 3 3 3
Now I am trying to find the satisfaction score immediately after updating the values.
and no.of ratings
My formula is for finding is satisfaction score is
attribute score[ (sum(r1)/no.of rating for r1) + (sum(r2)/no.of rating for r2)+(sum(r3)/no.of rating for r3)+..+(sum(r5)/no.of rating for r5)]
Where the total no.of ratings is (sum(no.of ratings for r1+ r2+ r3+..+r5))
For satisfaction score (attribute score/ total.no.of ratings)
So how can I find the statisfaction score.
I have kept in my ratings model as
after_create : update_post_average_rating
def update_post_average_rating
self.name. update_average_rating
end
and in my names model as
def update_average_rating
update_attributes(:satisfaction => self.ratings.average(:ratings))
end
Can any one tell me how to do this. I am unable to understand how can I do it.