Thursday, June 12, 2008

Add GET Parameter Options to paginating_find

I'm using the paginating_find plugin for my Rails app and I really wanted to add additional HTTP GET parameters to the page links that are created. Normally, when you include the pagination helper like this:

<%= paginating_links(@images) %>

you get the following URL: http://my.app.com/action?page=1

But I wanted this: http://my.app.com/action?page=1&view=detail

After poking around in the code, I noticed that the helper accepted a params hash (it just passes this to the default Rails link_to method), but I didn't know what format to use in the helper. So, after some trial and error with added puts statements (remember, if you change the plugin code, you need to restart WEBrick), this syntax ultimately worked:

<%= paginating_links(@images, options = {:params => {:view => @view}}) %>

where @images is the instance variable containing the objects to be paginated and @view is the instance variable containing a string that I want passed in the URL for the GET parameter called 'view'.

No comments: