Hey All,
What''s the right way to make a list of something (games in my case)
but filtered by various parameters?  For example, I have /game/list
showing all games, but if they specify /game/list/?
category=3&players=5 I want to show all games in that category that
allow 5 players.
Right now, I can get the category''s games by using
      if defined? params[:category]
        @games = Category.find(params[:category]).games;
      end
and I can get the players by using
      if params[:players].to_i > 0
        @games = Game.find(:all, :conditions => [''players =
?'',
params[:players]]);
      end
But how can I do both?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Any Ideas? I know how to do it with a straight SQL Query, but I''m not sure if there is a more ruby-like way On Jul 9, 8:04 am, Sean Clark Hess <seanh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hey All, > > What''s the right way to make a list of something (games in my case) > but filtered by various parameters? For example, I have /game/list > showing all games, but if they specify /game/list/? > category=3&players=5 I want to show all games in that category that > allow 5 players. > > Right now, I can get the category''s games by using > > if defined? params[:category] > @games = Category.find(params[:category]).games; > end > > and I can get the players by using > > if params[:players].to_i > 0 > @games = Game.find(:all, :conditions => [''players = ?'', > params[:players]]); > end > > But how can I do both?--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Straight SQL isn''t bad for this kind of stuff... @games
Game.find_by_sql("select *....)
But there are other ways too. Conditions can be built up programatically...
See Ben Curtis'' well-written article on this approach:
http://www.bencurtis.com/archives/2008/06/restful-searching-in-rails/
Or you could use something like ez_where
http://opensvn.csie.org/ezra/rails/plugins/dev/ez_where/README.txt
On Wed, Jul 9, 2008 at 9:57 AM, Sean Clark Hess
<seanhess-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> Any Ideas?  I know how to do it with a straight SQL Query, but I''m
not
> sure if there is a more ruby-like way
>
> On Jul 9, 8:04 am, Sean Clark Hess
<seanh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > Hey All,
> >
> > What''s the right way to make a list of something (games in my
case)
> > but filtered by various parameters?  For example, I have /game/list
> > showing all games, but if they specify /game/list/?
> > category=3&players=5 I want to show all games in that category
that
> > allow 5 players.
> >
> > Right now, I can get the category''s games by using
> >
> >       if defined? params[:category]
> >         @games = Category.find(params[:category]).games;
> >       end
> >
> > and I can get the players by using
> >
> >       if params[:players].to_i > 0
> >         @games = Game.find(:all, :conditions => [''players
= ?'',
> > params[:players]]);
> >       end
> >
> > But how can I do both?
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Thanks for the help! On Jul 9, 9:05 am, "Brian Hogan" <bpho...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Straight SQL isn''t bad for this kind of stuff... @games > Game.find_by_sql("select *....) > > But there are other ways too. Conditions can be built up programatically... > > See Ben Curtis'' well-written article on this approach: > > http://www.bencurtis.com/archives/2008/06/restful-searching-in-rails/ > > Or you could use something like ez_where > > http://opensvn.csie.org/ezra/rails/plugins/dev/ez_where/README.txt > > On Wed, Jul 9, 2008 at 9:57 AM, Sean Clark Hess <seanh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Any Ideas? I know how to do it with a straight SQL Query, but I''m not > > sure if there is a more ruby-like way > > > On Jul 9, 8:04 am, Sean Clark Hess <seanh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hey All, > > > > What''s the right way to make a list of something (games in my case) > > > but filtered by various parameters? For example, I have /game/list > > > showing all games, but if they specify /game/list/? > > > category=3&players=5 I want to show all games in that category that > > > allow 5 players. > > > > Right now, I can get the category''s games by using > > > > if defined? params[:category] > > > @games = Category.find(params[:category]).games; > > > end > > > > and I can get the players by using > > > > if params[:players].to_i > 0 > > > @games = Game.find(:all, :conditions => [''players = ?'', > > > params[:players]]); > > > end > > > > But how can I do both?--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---