Right way to clear page number from session?

4 views
Skip to first unread message

mobilemike

unread,
Dec 21, 2009, 1:16:13 PM12/21/09
to ActiveScaffold : Ruby on Rails plugin
I have a number of hard-coded links to named routes in my application.
This named routes affect filters used in the returned list view. In
effect, I've partly un-ajaxified AS so that I have more control over
what gets displayed. I have come across an issue when someone does the
following:

Bring up the default view which has no finder conditions applied, this
view is something like 18 pages long.
Move forward through the pages to page 4.
Use a link on the page to move to a filtered version of the data, one
that has less pages.
Since AS remembers that they were on page 4, but this list is only 2
pages long, I get a nil object error from the AS do_list method.

So, in my controller I run a before filter for updating the
table_config. I figure I could add something here that clears out the
page setting, but I'm not sure what to do.

- Mike Karolow

mobilemike

unread,
Dec 23, 2009, 10:50:48 PM12/23/09
to ActiveScaffold : Ruby on Rails plugin
I'll answer my own question, incase anyone needs it in the future.
This works, and actually has the side effect of clearing the current
page on a re-sort (which I feel is better behavior).

Add the following hack (it certainly feels hackish) in a before
filter:
params[:page] ||= 1

This way, if an action includes a page in the params (like using the
paginator), it will be respected. If not, the page will be reset.

Reply all
Reply to author
Forward
0 new messages