Hi - I''ve just started working with Rails, having come from a Cold Fusion background. I''m curious how best to deal with a huge result set. For example, I''m building an app that contains users. I''ve used scaffolding to setup my initial pages for CRUD operations on users. All that is great. The problem is, I''m going to end up with 1000+ users in this app once it''s done. Having people paginate through 1000 users to find the one they want seems a bit tedious. Is there a nice Rails way to handle this problem? Like some way to filter down the result list by last name, or user group, etc. i.e. take some input from the user and use that to make the pagination list smaller? Any help is appreciated. Thanks! Josh
You can add :conditions to the pagination which have query strings attached based on a search query. So for example, you could add a case if params[:lastname] conditions = [''lastname like ''%:lastname%'', {:lastname => params[:lastname]}] end paginate :users, :per_page => 50, :order => ''lastname'', :conditions => conditions Check out http://railsmanual.org/module/ActionController%3A%3APagination/paginate for more information. - Nb ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Nathaniel S. H. Brown http://nshb.net ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~> -----Original Message----- > From: rails-bounces@lists.rubyonrails.org > [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Josh Black > Sent: January 2, 2006 10:15 PM > To: rails@lists.rubyonrails.org > Subject: [Rails] Pagination Question > > Hi - > > I''ve just started working with Rails, having come from a Cold > Fusion background. I''m curious how best to deal with a huge > result set. For example, I''m building an app that contains > users. I''ve used scaffolding to setup my initial pages for > CRUD operations on users. > All that is great. The problem is, I''m going to end up with > 1000+ users in this app once it''s done. Having people > paginate through 1000 users to find the one they want seems a > bit tedious. Is there a nice Rails way to handle this > problem? Like some way to filter down the result list by > last name, or user group, etc. i.e. take some input from the > user and use that to make the pagination list smaller? Any > help is appreciated. Thanks! > > Josh > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Josh Black wrote:> Hi - > > I''ve just started working with Rails, having come from a Cold Fusion > background. I''m curious how best to deal with a huge result set. For > example, I''m building an app that contains users. I''ve used > scaffolding to setup my initial pages for CRUD operations on users. > All that is great. The problem is, I''m going to end up with 1000+ > users in this app once it''s done. Having people paginate through 1000 > users to find the one they want seems a bit tedious. Is there a nice > Rails way to handle this problem? Like some way to filter down the > result list by last name, or user group, etc. i.e. take some input > from the user and use that to make the pagination list smaller? Any > help is appreciated. Thanks!One word: autocomplete. Use an AJAX autocompleter to narrow the list in near-ish real-time, with a drop-box to select the relevant one. Much simpler than parameterised search pages, and more intuitive for the user, too. -- Alex
This sounds awesome. Is there any documentation or examples for something like this that I could look at? Thanks again for all the help. --- Alex Young <alex@blackkettle.org> wrote:> Josh Black wrote: > > Hi - > > > > I''ve just started working with Rails, having come from a Cold > Fusion > > background. I''m curious how best to deal with a huge result set. > For > > example, I''m building an app that contains users. I''ve used > > scaffolding to setup my initial pages for CRUD operations on users. > > > All that is great. The problem is, I''m going to end up with 1000+ > > users in this app once it''s done. Having people paginate through > 1000 > > users to find the one they want seems a bit tedious. Is there a > nice > > Rails way to handle this problem? Like some way to filter down the > > result list by last name, or user group, etc. i.e. take some input > > from the user and use that to make the pagination list smaller? > Any > > help is appreciated. Thanks! > > One word: autocomplete. Use an AJAX autocompleter to narrow the list > in > near-ish real-time, with a drop-box to select the relevant one. Much > > simpler than parameterised search pages, and more intuitive for the > user, too. > > -- > Alex > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On Jan 3, 2006, at 5:08 AM, Alex Young wrote:> One word: autocomplete. Use an AJAX autocompleter to narrow the > list in near-ish real-time, with a drop-box to select the relevant > one. Much simpler than parameterised search pages, and more > intuitive for the user, too.Apologies for changing the subject line, but I''m trying to use autocomplete and it''s not working. Relevant line from my view: <%= text_field_with_auto_complete (''dealing'', ''which_store'', {}, :skip_style=>true) %> relevant lines from my controller: def auto_complete_for_dealing_which_store search = params[:dealing][:which_store] @stores = Dealing.search(search) unless search.blank? render :partial => ''live_search'' end and my entire partial: <ul class="autocomplete_list"> <% for deal in @dealings.to_a %> <li class="autocomplete_item"><%= link deal.which_store, deal %></li> <% end %> </ul> Any idea? Please CC responses to me or they will get lost in the rest of the emails. Thanks! Cheers, Hasan Diwan <hasan.diwan@gmail.com> -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 186 bytes Desc: This is a digitally signed message part Url : http://wrath.rubyonrails.org/pipermail/rails/attachments/20060103/8fc3aa33/PGP.bin
Hasan Diwan wrote: <snip>> and my entire partial: > <ul class="autocomplete_list"> > <% for deal in @dealings.to_a %> > <li class="autocomplete_item"><%= link deal.which_store, deal %></li>What''s the ''link'' method? Do you mean ''link_to''? -- Alex