vwoo/last_request_url
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
LastRequestURL
===============
This Rails plugin will keep track of the last GET request URL. A common use case is to redirect the user back to where they were before attempting to login or logout.
The code is very simple, short, and easily monkey patched. Just override any of the methods defined in lib/vincent_woo/last_request_url.rb inside any of your controllers in order to fine tune anything.
Example
=======
To use this plugin, add the following into #{Rails.root}/app/controllers/application.rb:
class ApplicationController < ActionController::Base
include VincentWoo::LastRequestUrl
before_filter :track_last_request_url
end
To access the last request url from the controller or view, call the last_request_url method like in the following example:
redirect_to last_request_url
By default, a request is recorded only:
1) through the GET method
2) if the format is HTML or nothing
The reason for the HTML requirement is that users normally only want to be redirected to webpages. If the last request was for a PDF, for instance, the user will have to download it again.
If you have a different set of criteria, override #track_last_request_url? or additional_conditions_for_tracking_last_request_url in the controller to return a boolean.
If you want to be selective of which controller should or should not track the request url, then do:
skip_before_filter :track_last_request_url
Copyright (c) 2008-2009 Vincent Woo http://www.undefinedrange.com/
Released under the MIT license