Ok so this may seem simple but I don''t even know what to do here. This seems like some sort of "ruby math" maybe? Ok so here is what I want to do: I want users to submit a user rating from 1-10. How about a drop-down box? Then I want to submit the data into the db. ok so I can do all that. Now here is the thing. I have a bunch of "ratings". Each was an id, a game_id, and a rating. First off, do I need any other fields in the db? And second, how do I get an "average user rating". Maybe something like add up all the numbers, and divide them by the number of ratings for that game_id???? idk. Any help would be great =) - Jake -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jacob J. wrote:> Ok so this may seem simple but I don''t even know what to do here. This > seems like some sort of "ruby math" maybe? Ok so here is what I want to > do: I want users to submit a user rating from 1-10. How about a > drop-down box? Then I want to submit the data into the db. ok so I can > do all that. Now here is the thing. I have a bunch of "ratings". Each > was an id, a game_id, and a rating. First off, do I need any other > fields in the db? And second, how do I get an "average user rating". > Maybe something like add up all the numbers, and divide them by the > number of ratings for that game_id???? idk. Any help would be great =) > > - JakeSee: ActiveRecord::Calculations::ClassMethods -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
James Byrne wrote:> See: > ActiveRecord::Calculations::ClassMethodsSorry about that. Pushed the button too soon. Consider a table called "ratings" with columns "user_id" "game_id" & "rating" Game.average :rating, :conditions => [''game_id = ?'', 21] # gives average for game_id 21 Game.average :rating # gives average for all rows Game.count :conditions => [''rating > ?'', 5.5] # gives total number of ratings gt 5.5 etc. Most, nay all, relational database systems have basic tools like average, min, max, and count built right in, so ActiveRecord will usually (always) have a simple way to get at them. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
James Byrne wrote:> James Byrne wrote: > >> See: >> ActiveRecord::Calculations::ClassMethods > > Sorry about that. Pushed the button too soon. > > Consider a table called "ratings" with columns "user_id" "game_id" & > "rating"Table name should be "games" for the examples that I gave or else "Game." should be read as "Rating." in all instances. Must go to bed... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
James Byrne wrote:> James Byrne wrote: >> James Byrne wrote: >> >>> See: >>> ActiveRecord::Calculations::ClassMethods >> >> Sorry about that. Pushed the button too soon. >> >> Consider a table called "ratings" with columns "user_id" "game_id" & >> "rating" > > Table name should be "games" for the examples that I gave or else > "Game." should be read as "Rating." in all instances. Must go to bed...wow this whole thing is great. Thanks so much. It seems simple, I''ve just never really done anything in this part of rails yet. Thanks a bunch for the detailed help. I should be able to find the rest of the info in the API =) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---