How to update my satisfaction and no.of reviews coloumn in my table 1 coloumn

I am totally newbie in the rails and I have searched for my problem to
solve it then I found an example from
herehttp://stackoverflow.com/questions/12092964/update-post-attribute-when-new-rating-is-created.
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.

On 15 January 2014 01:57, raju [email protected] wrote:

I am totally newbie in the rails

First work right through a good tutorial such as railstutorial.org
(which is free to use online). That will show you the basics of
rails. Also look at the Rails Guides.

Colin