Forum: Ruby on Rails Pagination and custom routing

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Dave F. (Guest)
on 2006-03-03 22:15
Hello all, I'm new to RoR but loving leanrning it and wish i'd found it
earlier instead of spending so much time with PHP.

I have a problem with a custom routing and pagination... In my
application, users can save their favourite bookmarks, and can view each
others favourites. I have set up rooting so they can do this easily by
the URL using the following route -

map.connect ':username', :controller => 'links', :action => 'per_user'

This works fine and sends them to the correct controller, links, where
the action per_user paginates a list of bookmarks depending on the
username defined by :username in the map.connect above.

The action that generates the pages looks like this -

user = User.find_by_login(@params[:username])
@bookmark_pages, @bookmarks = paginate(:bookmarks, :conditions =>
['user_id = ?',])

The first page of results works fine, i can type for
instance, and i recieve the first page of my bookmarks.

The problem is with the rest of the pages, the link to page 2 appears as

where i'd like it to be

Is this a problem with my routing, I can't seem to figure this one out,
any help at all appreciated, thanks in advance.
Dave F. (Guest)
on 2006-03-04 00:15
Just sorted it, it was the order of the route mapping in routes.rb.
I had my custom route below the default :controller/:action/:id , so it
seems when paginate was generating the links this map was catching it
first. I just moved my route above this and paginate generates the URLs
as required.
This topic is locked and can not be replied to.