there is a case statement that basically handles that though if you define a valid list like that you can use the send method with couple sanity checks first. if !(params[:range] == "All") and params[:range].in? @range hobo_index Todo.send(params[:range].to_sym).apply_scopes(... else hobo_index Todo.apply_scopes(... end
not a that it's much cleaner or more understandable though. On Jun 10, 12:21 pm, storitel <[email protected]> wrote: > thanks Kevin. in case anyone else has the same kind of problem, where > you've got an index page dated items, and want to filter past, future > etc. > > my solution is as follows... > > in my index view i've added a filter (using your filter-menu-without- > no-option from another thread here) > > <div class="filter"> > Display by date: <filter-menu-without-no-option param- > name="range" options="&@range"/> > </div> > > in the model (possibly overkill, taken directly from railscasts...) > > named_scope :future, lambda { |*args |{:conditions => [ "date > ?", > (args.first || Date.today) ] }} > named_scope :overdue, lambda { |*args |{:conditions => [ "date < ?", > (args.first || Date.today) ] }} > named_scope :today, lambda { |*args |{:conditions => [ "date = ?", > (args.first || Date.today) ] }} > > then in the controller i have an index method with... > > @range = ["All","overdue","today","future"] > > if params[:range] == "future" > hobo_index Todo.future.apply_scopes(..... > > else if params[:range] == "overdue" > hobo_index Todo.overdue.apply_scopes(:search => > [params[:search], :name], > > else if params[:range] == "today" > hobo_index Todo.today.apply_scopes(:search => > [params[:search], :name], > > and so on. i expect there's a tider solution than my chain of ifs, but > it works for me :-) > > thanks again > Paul > > On 9 June, 23:38, kevinpfromnm <[email protected]> wrote: > > > I thought better of that last recommendation and decides a model > > method to return whichever scope would be more appropriate. > > > that way, you can have a sane default in the event of a improper > > submission. > > > On Jun 9, 4:37 pm, kevinpfromnm <[email protected]> wrote: > > > > you could do just a send but since you're getting that from a param > > > you'd better be careful with the input. object.send(:methodname,args) > > > runs methodname on the object. > > > > On Jun 9, 4:24 pm, storitel <[email protected]> wrote: > > > > > hi all > > > > I've more or less figured out how named scopes work - so now I have a > > > > Todo model with Todo.today, Todo.overdue and Todo.future :-) > > > > > And I've more or less got filter menu down too... > > > > @range = ["today","overdue","future"] > > > > > in my Todo_controller and > > > > > <filter-menu-without-no-option param-name="range" options="&@range"/> > > > > > gives me a filter for the user to choose which Todos he/she wants to > > > > see... > > > > > now all I need is the flash of insight on how to use the filter to > > > > trigger the scope? why am I so dense? > > > > > br > > > > Paul > > -- You received this message because you are subscribed to the Google Groups "Hobo Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.
