And it automatically adds the pagination links. If you look at the
HTML output in a browser, you should see the tags and classes used, so
that you can style them.
It may get slightly more complicated if you're including search
strings, sorting or other conditions, but so long as you can get your
params to the controller and into a :condition, it should play nice.
@title = "Search"
if params[:q]
query = params[:q]
# First find the user hits...
@users = User.find_with_ferret(query, :limit => :all)
# ...then the subhits.
infos = Info.find_with_ferret(query, :limit => :all)
# Now combine into one list of distinct users sorted by last
name.
hits = infos
@users.concat(hits.collect { |hit| hit.user }).uniq!
# Sort by last name (requires a spec for each user).
@users.each { |user| user.info ||= Info.new }
@users = @users.sort_by { |user| user.info.last_name }
end
At the moment, this returns results, but has no pagination
I'm not 100% what i'm meant to add and where, to allow it to paginate
properly
I would suggest that you start a new app just to learn how to use
pagination. RailsSpace is a good tutorial but there are several
"version of..." issues embedded in the code. Pagination is one.
1) "gem install mislav-will_paginate"
(or "sudo gem install mislav-will_paginate" if you must)
3) run "rails pagin" and create a throw-away app that will just
do pagination. I would suggest that you just have one model - Word -
and create a word index that paginates 10 words per page, then get
fancy and sort the words.
The simplest way to go is to have your words_controller.rb include:
One change from my previous - I misspoke when I identified a problem
with the view pagination controls under ruby 1.9. I've done some
added checking an determined that the problem is actually related to
Rails3.
So, as long as you're not out there on the bloody edge...