Hi there,
I have managed to overcome my search issue, and now I am able to
return users successfully.
I am now trying to paginate the results, so only 10 are displayed on
each page.
The paginate example in the RailsSpace book doesn’t work in my version
of rails (2.3.3). So – my question is:
Has anyone had this issue, and if so how was it overcome?
Or
Is there a simpler way to implement this to tidy the results up
Many Thanks
I’m not too hot with Ruby on Rails yet, so if anyone can help, in a
simple explanation kinda way, that would be cool! 
On Oct 28, 1:56 pm, RubyonRails_newbie [email protected]
wrote:
Has anyone had this issue, and if so how was it overcome?
pagination was removed from rails in 2.0. Get the will_paginate
plugin.
Fred
Sorry,
Has anyone managed to get the willl_paginate plugin to work?
The git hub site makes no sense, and the example isn’t clear enough
for me to know what im meant to be doing…
ie: What exactly do I need to put in the user.rb file in models
What goes in the controller
and what goes in the view?
I am new to this and understand sometings, but this isn’t too clear
for a beginner…
cheers
Hmmm… I must be missing something…
here’s what I have so far:
def search
@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
You should not need to add anything to your models, unless you want to
change the default number of fetched results per model.
In your controller, instead of doing
@things = Thing.find(:all, :conditions => whatever)
you can do this
@things = Thing.paginate(:page => params[:page], :conditions =>
whatever)
In your view you add
<%= will_paginate @things %>
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.
On Oct 28, 10:55 am, RubyonRails_newbie [email protected]
Ah. The documentation is assuming an ActiveRecord find, not
acts_as_ferret
google is your friend?
http://www.google.com/search?client=safari&rls=en&q=acts_as_ferret+pagination&ie=UTF-8&oe=UTF-8
On Oct 28, 11:35 am, RubyonRails_newbie [email protected]
On Wed, Oct 28, 2009 at 6:56 AM, RubyonRails_newbie <
[email protected]> wrote:
of rails (2.3.3). So – my question is:
simple explanation kinda way, that would be cool! 
If you’re working your way through RailsSpace, then I would recommend
reading this:
Good luck,
-Conrad
that’s what I am reading, and the code in there hasn’t helped solve
this issue!
hmmmm
when I try and add: @users = User.paginate_by_contents(@search.query,
:total_entries => User.total_hits(@search.query), :page => params
[:page],
:per_page => 10)
I get this in the browser:
You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.query
Nothing seems to run through it step by step…
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.
-
"gem install mislav-will_paginate"
(or “sudo gem install mislav-will_paginate” if you must)
NOTE: this is not the same gem as will_paginate.
-
Go to "http://github.com/mislav/will_paginate/blob/master/
README.rdoc" and keep this page up in your browser as you follow the
instructions.
-
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:
require ‘will_paginate’
def index
#@words = Word.all
@words = Word.paginate :page => :params[:page], :per_page => 10
.
.
.
And to have your index.html.erb include:
Listing words
<%= will_paginate @words %>
.
.
.
NOTE: there appears to be a bug related to the view pagination
controls under Ruby 1.9 - all’s good with 1.8 however.
On Oct 28, 5:56 pm, RubyonRails_newbie [email protected]
This is a great idea.
I always make mini projects to learn new functionality and then move it
to
my main project when I’ve got it working right.
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… 