Back button

Is there a way to implement a button that has exactly the same behavior
as the browser’s back button?

Try:

button_to “Back”, :back

Anthony Franco wrote:

Try:

button_to “Back”, :back

It does not have the same behavior.

If I understand the documentation, :back uses the referrer field.

Does Rails maintain a “per window” or “per tab” linked list of URLs?
visited?

I think this may be a bit more complicated than just using :back.

But thanks for the answer.

On Feb 17, 10:35 am, Ralph S. [email protected] wrote:

visited?

Nope. (although I suppose you maintain such a list by collecting the
referrer on each page view).
If javascript is an option then history.go(-1) takes you one back.
What’s wrong with the browser’s back button ?

Fred

I think this would do what you’re looking for.

<%= link_to ‘Back’, request.headers[‘HTTP_REFERER’] %>

Hope this helps,

On Feb 17, 6:02 am, Frederick C. [email protected]

Ralph S. wrote:

Is there a way to implement a button that has exactly the same behavior
as the browser’s back button?

You can do this with JavaScript – check out history.go() – but there’s
generally no point in doing so. The Back button is always available in
every browser I’m familiar with, and users expect to use it.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs