How to pass sorting values between pages

I have several values that need to get passed on every link on a page
that lists items. For example, as the user paginates, I need to keep
the current sort value, how many items to display on the page,
whether to show active or inactive items in the list, etc

In addition, I want them passed through edit actions as well. The
user edits a record, gets sent back to the list, it should be sorted
correctly, etc.

Currently I’m placing the relevant param values on every link, and
it’s just feeling cumbersome. I don’t want to place them in the
session, because then you can’t have two windows open looking at the
same list in different ways.

Any recommendations on the best method of doing this?

Thanks,
Brett

you can’t have two windows open looking at the same list in different ways.

Any recommendations on the best method of doing this?

Seems like sessions are perfect for this, but if your users open
multiple
windows to the same data, then your right you have problems.

Not sure it’s better, but you could generate a “window id” and pass that
around in your links, then store the rest in a session keyed by “window
id”…

?

-philip

You might consider writing a helper that re-implements link_to or
something and tag on the extra options there.

Chris

Thanks guys. I will have to look at the windows_id method and maybe
writing a link_to helper. Though there might be something out there
already.

Cheers,
Brett

On Saturday, May 13, 2006, at 8:50 AM, Brett W. wrote:

something and tag on the extra options there.
To: [email protected]

Rails mailing list
http://lists.rubyonrails.org/mailman/listinfo/rails
I did something like this a while back… the basic approach I ended up
using was to create a view_settings table and then I stored the YAML of
the params hash with the page_uri and the user_id.

The table looked like this, I think

id, :integer
uri, :string
user_id, :integer
params, :text

You can then use a before_filter in your controller to recover the
params hash, overwrite any params with values that were actually passed
with the request, and then render the page.

You can use an after_filter to update or create the appropriate entry
for the view. I would limit this before_filter to :only=>:list or other
actions that actually have settings to save, otherwise the table will
get huge and will end up with a lot of dead view_settings for deleted
records and such.

The advantgage of this method is that it transparently remembers the
state that each user left the page in last time they were there, and
this setting persists across sessions.

You could hack this approach a bit and have it remember settings for two
separate views to the same page. You would only need to find a
consistent way to make the ‘uri’ key different.

You could generate a unique window id (perhaps based on the current
time) and pass it in the params if one doesn’t already exist. This
could be added to the URI to make it a unique entry.

You would need some method to clean out old view_settings that don’t
apply anymore. If you use the unique window approach, you also won’t be
able to persist settings without a bit more work.

_Kevin