raju
2014-Jan-15 01:57 UTC
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
here<http://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.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/7d7dd7e8-b839-4f92-94f4-a7a01d2b747b%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.