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

8 views
Skip to first unread message

raju

unread,
Jan 14, 2014, 8:57:38 PM1/14/14
to rubyonra...@googlegroups.com

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.

Colin Law

unread,
Jan 15, 2014, 4:04:58 AM1/15/14
to rubyonra...@googlegroups.com
On 15 January 2014 01:57, raju <sesh...@gmail.com> 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
Reply all
Reply to author
Forward
0 new messages