Skip to content
JohnMunsch edited this page Sep 12, 2010 · 8 revisions

The original announcement of the code is probably the best resource available right now. It shows several simple examples of using the plugin. Be sure to check the comments on the blog posting, there are quite a few and the author seems to get email about new comments to his blog because he continues to respond to requests for information and comments.

Further documentation is available at Google Code

Pagination

I can’t say this is a definitive example of everything you need to do for pagination but maybe it will help you get started. I confess I’m still not really good with pagination so I don’t know everything that has to be done. But the following worked for me for part of my needs.

One of the examples given by Phil Sergi for getting email from acts_as_messageable is as follows:

todd.mailbox[:inbox].latest_mail

If you install the will_paginate gem according to the instructions given here, then you can change that call as follows:

todd.mailbox[:inbox].latest_mail.paginate(:page => params[:page], :per_page => 10)

and you will get a paginated set of 10 at a time. Assuming you assign that to a variable in a controller before you go to a view like so:

@inbox = todd.mailbox[:inbox].latest_mail.paginate(:page => params[:page], :per_page => 10)

then in the view you can display the contents of @inbox (which will only show ten items at most) and then add this after it:

<%= will_paginate @inbox %>

and you’ll get pagination links like so:

« Previous 1 2 3 Next »

The links should work automatically because they will go to the same page the user is on currently but specify a different value for the :page variable and thus the pagination will shift to another page.

Troubleshooting

After you’ve run the generator you will run ‘rake db:migrate’ and then immediately get the error: “Multiple migrations have the version number 20081004002826”

The number will vary but trust me, the bug’s the same. It’s because four different migrations were just generated (look in db/migrate to find them) and all four have the same timestamp at the beginning of the filename. That timestamp is how Rails knows which migration comes before another migration (it’s a Rails V2 change to work better with groups of programmers).

There are a couple of solutions you can use. One is to take all four migrations and edit the table builds and table drops into just one self.up and self.down in a single file. Get rid of the other three files, name it something sensible and it will work.

Another alternative is to slightly change the timestamps at the beginning of the four files. All four should still start the same way, but you can increment the numbers by one, two, and three on three of the files and when you run the migration again it won’t see a conflict.

Clone this wiki locally