Frank Kim wrote: > I have a model, let's call it Player. > > It has many Trophies. > > How do I do a simple query in Rails in my controller that will return > let's say all Players that have more than 5 tropies? > > Sorry for the dumb question but I can't figure it out. :-) > > -- > Frank Kim > http://betweengo.com/
I would recommend checking out the searchlogic gem (http://github.com/binarylogic/searchlogic). You can then do something like (I haven't checked the exact format of the method but it will be something along these lines): Player.trophies_count_greater_than(5) or used your own named scopes. I'd also think about maybe putting this as a method in your model i.e. def self.has_more_trophies_than(trophy_count) Player.trophies_count_greater_than(trophy_count) end Then you can call it from the controller like so: Player.has_more_trophies_than(5) -- 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-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.