The Accelerate HR Blog
My Back Pages (Mon Nov 12 2007)
ACCELERATE HR is a database with complex links, and there are often several access points for a single page. How then to return to the correct access page when you've finished working on the destination page?
Let's take a simple example. We're working on overtime entry for a single department. There are two possible access points for the new overtime entry page. One is a listing of the business's departments showing existing overtime records over the last 12 months. The second is a similar department listing, but this time the records are for a single month. Making it a bit more complicated, the month can be set by the user. When we return to this page, we want the same month's data to be displayed.
OK, you say. Follow the link to the overtime entry page and then use the browser's Back button. But it's not that simple. What if the user has processed new overtime data and has been taken to a 'Show' page? That's where the browser button is going to take you, not back to the original department listing - or not directly anyway.
This is the simple method I find I'm using lots.
Step 1. In the controller def for each of the possible access pages, add the line:
Step 2. In the controller referencing the destination page, add:
Step 3. Add a link to goback in the view for the destination page. Something like:
And that's it. You're back to the page where you started. If your access page was the month's overtime listing for October this year, it's October you'll go back to. If November, then November. Or the records for the last 12 months. And this isn't just for page redirects from the view. You can redirect_to session[:return_to] in your controller updates and creates too.
But there's one more reason why this approach wins hands down over the browser Back button. Suppose you've changed the data from the destination page - in my example, we've added new overtime. And suppose there's a reference to the model data on the access page - a summary of the overtime totals calculated in the model, say. Using the method I've described here, the totals will be recalculated as you return to the access page. Not so with the browser Back button. You'll see the original cached data.
And I suppose that brings us on to caching. But that's for another time.