Forum: Ruby on Rails Pagination Question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
984dc3a7004a25df6bbed6ff479f1d0b?d=identicon&s=25 Josh Black (Guest)
on 2006-01-03 07:16
(Received via mailing list)
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
00e3a96684ab390a350b0271e98741d3?d=identicon&s=25 Nshbrown Nshbrown (nshb)
on 2006-01-03 10:36
(Received via mailing list)
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%...
for
more information.

- Nb

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Nathaniel S. H. Brown                           http://nshb.net
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-01-03 14:06
(Received via mailing list)
Josh Black wrote:
> 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.
984dc3a7004a25df6bbed6ff479f1d0b?d=identicon&s=25 Josh Black (Guest)
on 2006-01-03 19:00
(Received via mailing list)
This sounds awesome.  Is there any documentation or examples for
something like this that I could look at?  Thanks again for all the
help.
895a112c66d93cefcd06d2cf371219e6?d=identicon&s=25 Hasan Diwan (Guest)
on 2006-01-03 20:30
(Received via mailing list)
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>
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-01-04 12:06
(Received via mailing list)
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'?
This topic is locked and can not be replied to.