DAN
2006-Aug-03 15:04 UTC
[Rails] Strategy for persisting row filter variables in pagination?
I have my list view filtering rows shown within the table <tr> tags like most of the introductory tutorials do. As I''m adding a few dozen entries I''m noticing the standard scaffolding pagination doesn''t pick up the number of rows from the filter since it is not being passed the number of rows returned within the scope of the filter statement.>From a tactical point I''m wondering if there''s a proper way to approachthis. Should I move my row filter statements into a a method within a helper that can then be called at top of the list view for the entire page? Or perhaps separate partial view files should be used with different filter statements at top of each? Or perhaps there''s someother way I''m not seeing right off. I''m imagining the pagination link_to''s will need to include the filter variables so they are persistent also. So ":s => "Summer", :c => "Beverage", :t => "Cold" creates urls with added "?s=Summer&c=Beverages&t=Cold" for example. Is there a prettier way to persist the variables? Maybe iterate through possible #? of params within the method? Thanks, DAN -- Posted via http://www.ruby-forum.com/.
Mike Garey
2006-Aug-03 16:23 UTC
[Rails] Strategy for persisting row filter variables in pagination?
On 8/3/06, DAN <daniel@freelancewebdesigner.com> wrote:> I have my list view filtering rows shown within the table <tr> tags like > most of the introductory tutorials do. As I''m adding a few dozen entries > I''m noticing the standard scaffolding pagination doesn''t pick up the > number of rows from the filter since it is not being passed the number > of rows returned within the scope of the filter statement. > > >From a tactical point I''m wondering if there''s a proper way to approach > this. Should I move my row filter statements into a a method within a > helper that can then be called at top of the list view for the entire > page? Or perhaps separate partial view files should be used with > different filter statements at top of each? Or perhaps there''s someother > way I''m not seeing right off. > > I''m imagining the pagination link_to''s will need to include the filter > variables so they are persistent also. So ":s => "Summer", :c => > "Beverage", :t => "Cold" creates urls with added > "?s=Summer&c=Beverages&t=Cold" for example. Is there a prettier way to > persist the variables? Maybe iterate through possible #? of params > within the method?I store my filter conditions into a session variable, since it gets really ugly when you''ve got more than a half a dozen filtering conditions. Mike
DAN
2006-Aug-03 18:09 UTC
[Rails] Re: Strategy for persisting row filter variables in paginati
I haven''t got it working yet, but maybe this is the right direction? In my snacks_controller.rb I''m playing with using: def list @s = @params[''s''] @c = @params[''c''] @t = @params[''t''] @snacks = Snack.find(:all, @s == @snacks.season, @c == @snacks.category, @t == @snacks.temp) @snack_pages, @snacks = paginate :snacks, :per_page => 5 end This way paginate should be getting the rows from the @snacks find query, right? I''m getting "undefined method `season'' for #<Array:0x24e6b84>" currently. It doesn''t seem to recognize the current rows season_id table column for some reason, even if I explicitly use @snacks.season_id. Any suggestions appreciated. -- Posted via http://www.ruby-forum.com/.
DAN
2006-Aug-03 23:45 UTC
[Rails] Re: Strategy for persisting row filter variables in paginati
Well I''ve been working at this for about five hours now and I can''t seem to get beyond the basics in RoR. I''ve read and reread through a couple more tutorials, dug through my Pick Axe and Ruby for Rails books, and tried a few more experiments but still not making any progress. It''s great seeing how a basic application can be created in 15 minutes in the tutorials but creating a more evolved app seems to be a much more complicated process. To try and further my progress I''ve posted a live working example with code and notes so people can see what I am describing. It''s currently posted at: http://www.freelancewebdesigner.com/rails/menu/public/snacks. This is a clean rewrite starting over from the beginning so hopefully it''s straight forward. None Hopefully someone knows how I can get the pagination to work properly while showing only certain rows. Thanks in advance for any enlightenment. -- Posted via http://www.ruby-forum.com/.
Kevin Olbrich
2006-Aug-04 03:20 UTC
[Rails] Re: Strategy for persisting row filter variables in paginati
On Thursday, August 03, 2006, at 7:59 PM, DAN wrote:>I haven''t got it working yet, but maybe this is the right direction? > >In my snacks_controller.rb I''m playing with using: > >def list > @s = @params[''s''] > @c = @params[''c''] > @t = @params[''t''] > @snacks = Snack.find(:all, @s == @snacks.season, @c =>@snacks.category, @t == @snacks.temp) > @snack_pages, @snacks = paginate :snacks, :per_page => 5 >end > >This way paginate should be getting the rows from the @snacks find >query, right? > >I''m getting "undefined method `season'' for #<Array:0x24e6b84>" >currently. It doesn''t seem to recognize the current rows season_id table >column for some reason, even if I explicitly use @snacks.season_id. > >Any suggestions appreciated. > >-- >Posted via http://www.ruby-forum.com/. >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/railstry this... ==== controller ===def list @s = params[''s''] @c = params[''c''] @t = params[''t''] #use params[:a] instead of @params[:a] @snacks = Snack.find(:all, :conditions=>["season = ? and category = ? and temp = ?",s,c,t]) # returns an Array of snacks @snack_pages, @snacks = paginate :snacks, :per_page => 5 end ==== view === <% for snack in @snacks %> <%= snack.season %> <% end %> _Kevin www.sciwerks.com -- Posted with http://DevLists.com. Sign up and save your mailbox.
Jim Morris
2006-Aug-04 21:10 UTC
[Rails] Re: Strategy for persisting row filter variables in paginati
I''m not sure how that would work either, as the call to paginate will overwrite the @snacks created in the previous line. How about this? @snack_pages = Paginator.new self, Snack.count, 10, @params[''page''] @snacks = Snack.find :all, :conditions=>["season = ? and category = ? and temp = ?",s,c,t]) :limit => @snack_pages.items_per_page, :offset => @snack_pages.current.offset Kevin Olbrich wrote:> try this... > > ==== controller ===> def list > @s = params[''s''] > @c = params[''c''] > @t = params[''t''] #use params[:a] instead of @params[:a] > @snacks = Snack.find(:all, :conditions=>["season = ? and category = ? > and temp = ?",s,c,t]) > # returns an Array of snacks > @snack_pages, @snacks = paginate :snacks, :per_page => 5 > end > > ==== view ===> > <% for snack in @snacks %> > <%= snack.season %> > <% end %> > > _Kevin > www.sciwerks.com >-- Jim Morris, http://blog.wolfman.com