paginate issues

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! :slight_smile:

is this the answer im looking for perhaps?

http://api.rubyonrails.org/classes/ActionController/Pagination.html

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?

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

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.

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

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

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......

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! :slight_smile:

If you’re working your way through RailsSpace, then I would recommend

reading this:

http://railsspace.com/

Good luck,

-Conrad

that's what I am reading, and the code in there hasn't helped solve this issue!

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)

NOTE: this is not the same gem as will_paginate.

2) 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.

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:

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:

<h1>Listing words</h1> <%= 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.

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... :slight_smile: