because I am a grasshopper... Now that I can sort my ''list''...is there a logical way of not repeating myself to having essentially the same list view with multiple sorts? i.e. def list_cl # ordered by clients last name @placement_pages, @placements = paginate( :placements, :include => [:client], :order_by => ''clients.last_name'', :per_page => 14) end def list_fac # ordered by facility @placement_pages, @placements = paginate( :placements, :include => [:facility], :order_by => ''facilities.name'', :per_page => 14) end etc. and then have links at the top of each column header to sort... <%= link_to ''Client'', :action => ''list_cl'' %> <%= link_to ''Facility'', :action => ''list_fac'' %> ... Do I just have one ''def list'' and then use something like a ''case'' statement? If so, how do I tell it from the link_to which value? Craig
Pass an extra parameter after the action. <%= link_to ''Client'', :action => ''list'', :sort_by => ''client'' %> Estelle. On 2/7/06, Craig White <craigwhite@azapple.com> wrote:> because I am a grasshopper... > > Now that I can sort my ''list''...is there a logical way of not repeating > myself to having essentially the same list view with multiple sorts? > > i.e. > > def list_cl > # ordered by clients last name > @placement_pages, @placements = paginate( > :placements, > :include => [:client], > :order_by => ''clients.last_name'', > :per_page => 14) > end > > def list_fac > # ordered by facility > @placement_pages, @placements = paginate( > :placements, > :include => [:facility], > :order_by => ''facilities.name'', > :per_page => 14) > end > > etc. > > and then have links at the top of each column header to sort... > > <%= link_to ''Client'', :action => ''list_cl'' %> > <%= link_to ''Facility'', :action => ''list_fac'' %> > ... > > Do I just have one ''def list'' and then use something like a ''case'' > statement? If so, how do I tell it from the link_to which value? > > Craig > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
OK then :sort_by becomes sort of an instance variable then? It doesn''t really create the ''order_by'' on its own right? Craig On Tue, 2006-02-07 at 20:32 -0800, Estelle Winterflood wrote:> Pass an extra parameter after the action. > > <%= link_to ''Client'', :action => ''list'', :sort_by => ''client'' %> > > Estelle. > > On 2/7/06, Craig White <craigwhite@azapple.com> wrote: > > because I am a grasshopper... > > > > Now that I can sort my ''list''...is there a logical way of not repeating > > myself to having essentially the same list view with multiple sorts? > > > > i.e. > > > > def list_cl > > # ordered by clients last name > > @placement_pages, @placements = paginate( > > :placements, > > :include => [:client], > > :order_by => ''clients.last_name'', > > :per_page => 14) > > end > > > > def list_fac > > # ordered by facility > > @placement_pages, @placements = paginate( > > :placements, > > :include => [:facility], > > :order_by => ''facilities.name'', > > :per_page => 14) > > end > > > > etc. > > > > and then have links at the top of each column header to sort... > > > > <%= link_to ''Client'', :action => ''list_cl'' %> > > <%= link_to ''Facility'', :action => ''list_fac'' %> > > ... > > > > Do I just have one ''def list'' and then use something like a ''case'' > > statement? If so, how do I tell it from the link_to which value? > > > > Craig > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
It becomes available via param[:sort_by] -- -- Tom Mornini On Feb 7, 2006, at 9:18 PM, Craig White wrote:> OK then :sort_by becomes sort of an instance variable then? It doesn''t > really create the ''order_by'' on its own right? > > Craig > > On Tue, 2006-02-07 at 20:32 -0800, Estelle Winterflood wrote: >> Pass an extra parameter after the action. >> >> <%= link_to ''Client'', :action => ''list'', :sort_by => ''client'' %> >> >> Estelle. >> >> On 2/7/06, Craig White <craigwhite@azapple.com> wrote: >>> because I am a grasshopper... >>> >>> Now that I can sort my ''list''...is there a logical way of not >>> repeating >>> myself to having essentially the same list view with multiple sorts? >>> >>> i.e. >>> >>> def list_cl >>> # ordered by clients last name >>> @placement_pages, @placements = paginate( >>> :placements, >>> :include => [:client], >>> :order_by => ''clients.last_name'', >>> :per_page => 14) >>> end >>> >>> def list_fac >>> # ordered by facility >>> @placement_pages, @placements = paginate( >>> :placements, >>> :include => [:facility], >>> :order_by => ''facilities.name'', >>> :per_page => 14) >>> end >>> >>> etc. >>> >>> and then have links at the top of each column header to sort... >>> >>> <%= link_to ''Client'', :action => ''list_cl'' %> >>> <%= link_to ''Facility'', :action => ''list_fac'' %> >>> ... >>> >>> Do I just have one ''def list'' and then use something like a ''case'' >>> statement? If so, how do I tell it from the link_to which value? >>> >>> Craig >>> >>> _______________________________________________ >>> Rails mailing list >>> Rails@lists.rubyonrails.org >>> http://lists.rubyonrails.org/mailman/listinfo/rails >>> >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Ok - I''m tugging at it... <%= link_to ''Placements'', :controller => ''placements'', :action => ''list'', :case_manager_id => case_manager %> calls placements_controller.rb this works... def list @placement_pages, @placements = paginate( :placements, :conditions => ["placements.case_manager_id = ?", ''15''], :include => [:client], :order_by => ''clients.last_name'', :per_page => 14) end or :conditions => "placements.case_manager_id = "15", but :conditions => "placements.case_manager_id params[:case_manager_id], gives me the syntax error near : # the :conditions line... (whether I use param or params - I don''t understand the difference between the two terms). and I can see from <% debug params %> !map:HashWithIndifferentAccess action: list case_manager_id: "15" controller: placements {"action"=>"list", "case_manager_id"=>"15", "controller"=>"placements"} that case_manager_id with value of 15 is coming through when I simply comment out the conditions line altogether. I''ve been playing with this but it''s the same form as the '':sort_by'' function so when I get one, I get both. On Tue, 2006-02-07 at 22:07 -0800, Tom Mornini wrote:> It becomes available via param[:sort_by] > > -- > -- Tom Mornini > > On Feb 7, 2006, at 9:18 PM, Craig White wrote: > > > OK then :sort_by becomes sort of an instance variable then? It doesn''t > > really create the ''order_by'' on its own right? > > > > Craig > > > > On Tue, 2006-02-07 at 20:32 -0800, Estelle Winterflood wrote: > >> Pass an extra parameter after the action. > >> > >> <%= link_to ''Client'', :action => ''list'', :sort_by => ''client'' %> > >> > >> Estelle. > >> > >> On 2/7/06, Craig White <craigwhite@azapple.com> wrote: > >>> because I am a grasshopper... > >>> > >>> Now that I can sort my ''list''...is there a logical way of not > >>> repeating > >>> myself to having essentially the same list view with multiple sorts? > >>> > >>> i.e. > >>> > >>> def list_cl > >>> # ordered by clients last name > >>> @placement_pages, @placements = paginate( > >>> :placements, > >>> :include => [:client], > >>> :order_by => ''clients.last_name'', > >>> :per_page => 14) > >>> end > >>> > >>> def list_fac > >>> # ordered by facility > >>> @placement_pages, @placements = paginate( > >>> :placements, > >>> :include => [:facility], > >>> :order_by => ''facilities.name'', > >>> :per_page => 14) > >>> end > >>> > >>> etc. > >>> > >>> and then have links at the top of each column header to sort... > >>> > >>> <%= link_to ''Client'', :action => ''list_cl'' %> > >>> <%= link_to ''Facility'', :action => ''list_fac'' %> > >>> ... > >>> > >>> Do I just have one ''def list'' and then use something like a ''case'' > >>> statement? If so, how do I tell it from the link_to which value? > >>> > >>> Craig > >>> > >>> _______________________________________________ > >>> Rails mailing list > >>> Rails@lists.rubyonrails.org > >>> http://lists.rubyonrails.org/mailman/listinfo/rails > >>> > >> _______________________________________________ > >> Rails mailing list > >> Rails@lists.rubyonrails.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Try this: :conditions => ["placements.case_manager_id = ?", params[:case_manager_id] ], On 2/7/06, Craig White <craigwhite@azapple.com> wrote:> Ok - I''m tugging at it... > > <%= link_to ''Placements'', :controller => ''placements'', :action > => ''list'', :case_manager_id => case_manager %> > > calls placements_controller.rb > > this works... > def list > @placement_pages, @placements = paginate( > :placements, > :conditions => ["placements.case_manager_id = ?", ''15''], > :include => [:client], > :order_by => ''clients.last_name'', > :per_page => 14) > end > or > :conditions => "placements.case_manager_id = "15", > but > :conditions => "placements.case_manager_id > params[:case_manager_id], > > gives me the syntax error near : # the :conditions line... (whether I > use param or params - I don''t understand the difference between the two > terms). > > and I can see from <% debug params %> > !map:HashWithIndifferentAccess > action: list > case_manager_id: "15" > controller: placements > {"action"=>"list", "case_manager_id"=>"15", "controller"=>"placements"} > > that case_manager_id with value of 15 is coming through when I simply > comment out the conditions line altogether. > > I''ve been playing with this but it''s the same form as the '':sort_by'' > function so when I get one, I get both. > > > > On Tue, 2006-02-07 at 22:07 -0800, Tom Mornini wrote: > > It becomes available via param[:sort_by] > > > > -- > > -- Tom Mornini > > > > On Feb 7, 2006, at 9:18 PM, Craig White wrote: > > > > > OK then :sort_by becomes sort of an instance variable then? It doesn''t > > > really create the ''order_by'' on its own right? > > > > > > Craig > > > > > > On Tue, 2006-02-07 at 20:32 -0800, Estelle Winterflood wrote: > > >> Pass an extra parameter after the action. > > >> > > >> <%= link_to ''Client'', :action => ''list'', :sort_by => ''client'' %> > > >> > > >> Estelle. > > >> > > >> On 2/7/06, Craig White <craigwhite@azapple.com> wrote: > > >>> because I am a grasshopper... > > >>> > > >>> Now that I can sort my ''list''...is there a logical way of not > > >>> repeating > > >>> myself to having essentially the same list view with multiple sorts? > > >>> > > >>> i.e. > > >>> > > >>> def list_cl > > >>> # ordered by clients last name > > >>> @placement_pages, @placements = paginate( > > >>> :placements, > > >>> :include => [:client], > > >>> :order_by => ''clients.last_name'', > > >>> :per_page => 14) > > >>> end > > >>> > > >>> def list_fac > > >>> # ordered by facility > > >>> @placement_pages, @placements = paginate( > > >>> :placements, > > >>> :include => [:facility], > > >>> :order_by => ''facilities.name'', > > >>> :per_page => 14) > > >>> end > > >>> > > >>> etc. > > >>> > > >>> and then have links at the top of each column header to sort... > > >>> > > >>> <%= link_to ''Client'', :action => ''list_cl'' %> > > >>> <%= link_to ''Facility'', :action => ''list_fac'' %> > > >>> ... > > >>> > > >>> Do I just have one ''def list'' and then use something like a ''case'' > > >>> statement? If so, how do I tell it from the link_to which value? > > >>> > > >>> Craig > > >>> > > >>> _______________________________________________ > > >>> Rails mailing list > > >>> Rails@lists.rubyonrails.org > > >>> http://lists.rubyonrails.org/mailman/listinfo/rails > > >>> > > >> _______________________________________________ > > >> Rails mailing list > > >> Rails@lists.rubyonrails.org > > >> http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
looks like this is going to have to wait until morning...I can''t seem to stay connected to remote terminal now...somewhat spotty old dish technology at clients until they move... ;-( I will certainly try it...you have been spot on. Thanks Craig On Tue, 2006-02-07 at 23:03 -0800, Estelle Winterflood wrote:> Try this: > > :conditions => ["placements.case_manager_id = ?", params[:case_manager_id] ], > > > On 2/7/06, Craig White <craigwhite@azapple.com> wrote: > > Ok - I''m tugging at it... > > > > <%= link_to ''Placements'', :controller => ''placements'', :action > > => ''list'', :case_manager_id => case_manager %> > > > > calls placements_controller.rb > > > > this works... > > def list > > @placement_pages, @placements = paginate( > > :placements, > > :conditions => ["placements.case_manager_id = ?", ''15''], > > :include => [:client], > > :order_by => ''clients.last_name'', > > :per_page => 14) > > end > > or > > :conditions => "placements.case_manager_id = "15", > > but > > :conditions => "placements.case_manager_id > > params[:case_manager_id], > > > > gives me the syntax error near : # the :conditions line... (whether I > > use param or params - I don''t understand the difference between the two > > terms). > > > > and I can see from <% debug params %> > > !map:HashWithIndifferentAccess > > action: list > > case_manager_id: "15" > > controller: placements > > {"action"=>"list", "case_manager_id"=>"15", "controller"=>"placements"} > > > > that case_manager_id with value of 15 is coming through when I simply > > comment out the conditions line altogether. > > > > I''ve been playing with this but it''s the same form as the '':sort_by'' > > function so when I get one, I get both. > > > > > > > > On Tue, 2006-02-07 at 22:07 -0800, Tom Mornini wrote: > > > It becomes available via param[:sort_by] > > > > > > -- > > > -- Tom Mornini > > > > > > On Feb 7, 2006, at 9:18 PM, Craig White wrote: > > > > > > > OK then :sort_by becomes sort of an instance variable then? It doesn''t > > > > really create the ''order_by'' on its own right? > > > > > > > > Craig > > > > > > > > On Tue, 2006-02-07 at 20:32 -0800, Estelle Winterflood wrote: > > > >> Pass an extra parameter after the action. > > > >> > > > >> <%= link_to ''Client'', :action => ''list'', :sort_by => ''client'' %> > > > >> > > > >> Estelle. > > > >> > > > >> On 2/7/06, Craig White <craigwhite@azapple.com> wrote: > > > >>> because I am a grasshopper... > > > >>> > > > >>> Now that I can sort my ''list''...is there a logical way of not > > > >>> repeating > > > >>> myself to having essentially the same list view with multiple sorts? > > > >>> > > > >>> i.e. > > > >>> > > > >>> def list_cl > > > >>> # ordered by clients last name > > > >>> @placement_pages, @placements = paginate( > > > >>> :placements, > > > >>> :include => [:client], > > > >>> :order_by => ''clients.last_name'', > > > >>> :per_page => 14) > > > >>> end > > > >>> > > > >>> def list_fac > > > >>> # ordered by facility > > > >>> @placement_pages, @placements = paginate( > > > >>> :placements, > > > >>> :include => [:facility], > > > >>> :order_by => ''facilities.name'', > > > >>> :per_page => 14) > > > >>> end > > > >>> > > > >>> etc. > > > >>> > > > >>> and then have links at the top of each column header to sort... > > > >>> > > > >>> <%= link_to ''Client'', :action => ''list_cl'' %> > > > >>> <%= link_to ''Facility'', :action => ''list_fac'' %> > > > >>> ... > > > >>> > > > >>> Do I just have one ''def list'' and then use something like a ''case'' > > > >>> statement? If so, how do I tell it from the link_to which value? > > > >>> > > > >>> Craig > > > >>> > > > >>> _______________________________________________ > > > >>> Rails mailing list > > > >>> Rails@lists.rubyonrails.org > > > >>> http://lists.rubyonrails.org/mailman/listinfo/rails > > > >>> > > > >> _______________________________________________ > > > >> Rails mailing list > > > >> Rails@lists.rubyonrails.org > > > >> http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > _______________________________________________ > > > > Rails mailing list > > > > Rails@lists.rubyonrails.org > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
*** bing *** You are truly remarkable. On Tue, 2006-02-07 at 23:03 -0800, Estelle Winterflood wrote:> Try this: > > :conditions => ["placements.case_manager_id = ?", params[:case_manager_id] ], > > > On 2/7/06, Craig White <craigwhite@azapple.com> wrote: > > Ok - I''m tugging at it... > > > > <%= link_to ''Placements'', :controller => ''placements'', :action > > => ''list'', :case_manager_id => case_manager %> > > > > calls placements_controller.rb > > > > this works... > > def list > > @placement_pages, @placements = paginate( > > :placements, > > :conditions => ["placements.case_manager_id = ?", ''15''], > > :include => [:client], > > :order_by => ''clients.last_name'', > > :per_page => 14) > > end > > or > > :conditions => "placements.case_manager_id = "15", > > but > > :conditions => "placements.case_manager_id > > params[:case_manager_id], > > > > gives me the syntax error near : # the :conditions line... (whether I > > use param or params - I don''t understand the difference between the two > > terms). > > > > and I can see from <% debug params %> > > !map:HashWithIndifferentAccess > > action: list > > case_manager_id: "15" > > controller: placements > > {"action"=>"list", "case_manager_id"=>"15", "controller"=>"placements"} > > > > that case_manager_id with value of 15 is coming through when I simply > > comment out the conditions line altogether. > > > > I''ve been playing with this but it''s the same form as the '':sort_by'' > > function so when I get one, I get both. > > > > > > > > On Tue, 2006-02-07 at 22:07 -0800, Tom Mornini wrote: > > > It becomes available via param[:sort_by] > > > > > > -- > > > -- Tom Mornini > > > > > > On Feb 7, 2006, at 9:18 PM, Craig White wrote: > > > > > > > OK then :sort_by becomes sort of an instance variable then? It doesn''t > > > > really create the ''order_by'' on its own right? > > > > > > > > Craig > > > > > > > > On Tue, 2006-02-07 at 20:32 -0800, Estelle Winterflood wrote: > > > >> Pass an extra parameter after the action. > > > >> > > > >> <%= link_to ''Client'', :action => ''list'', :sort_by => ''client'' %> > > > >> > > > >> Estelle. > > > >> > > > >> On 2/7/06, Craig White <craigwhite@azapple.com> wrote: > > > >>> because I am a grasshopper... > > > >>> > > > >>> Now that I can sort my ''list''...is there a logical way of not > > > >>> repeating > > > >>> myself to having essentially the same list view with multiple sorts? > > > >>> > > > >>> i.e. > > > >>> > > > >>> def list_cl > > > >>> # ordered by clients last name > > > >>> @placement_pages, @placements = paginate( > > > >>> :placements, > > > >>> :include => [:client], > > > >>> :order_by => ''clients.last_name'', > > > >>> :per_page => 14) > > > >>> end > > > >>> > > > >>> def list_fac > > > >>> # ordered by facility > > > >>> @placement_pages, @placements = paginate( > > > >>> :placements, > > > >>> :include => [:facility], > > > >>> :order_by => ''facilities.name'', > > > >>> :per_page => 14) > > > >>> end > > > >>> > > > >>> etc. > > > >>> > > > >>> and then have links at the top of each column header to sort... > > > >>> > > > >>> <%= link_to ''Client'', :action => ''list_cl'' %> > > > >>> <%= link_to ''Facility'', :action => ''list_fac'' %> > > > >>> ... > > > >>> > > > >>> Do I just have one ''def list'' and then use something like a ''case'' > > > >>> statement? If so, how do I tell it from the link_to which value? > > > >>> > > > >>> Craig > > > >>> > > > >>> _______________________________________________ > > > >>> Rails mailing list > > > >>> Rails@lists.rubyonrails.org > > > >>> http://lists.rubyonrails.org/mailman/listinfo/rails > > > >>> > > > >> _______________________________________________ > > > >> Rails mailing list > > > >> Rails@lists.rubyonrails.org > > > >> http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > _______________________________________________ > > > > Rails mailing list > > > > Rails@lists.rubyonrails.org > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails