R – How to tell in Rails controller whether user used back button


I need to check in a rails controller whether the user used the back button to come back to the page. Is there a specific method for this?

Best Solution

Telling that a user used the back button is very hard (maybe impossible?) for the reason Shtééf commented already.

But, you can make sure the page is fetched again from your webserver (instead of grabbed from the local cache), by sending some custom headers with it telling that the page should not be cached. More information on these headers can be found on Best way to disable client caching, Why both no-cache and no-store should be used in HTTP response? or take a look at these questions.

If you keep track on which page(s) the user has been you can see whether s/he returned to the previous page, which might indicate that the back button was used.