# Back button

**URL:** <https://discuss.rubyonrails.org/t/back-button/49424>\
**Category:** rubyonrails-talk\
**Created:** [February 17, 2010, 5:14am UTC](https://discuss.rubyonrails.org/t/back-button/49424 "2010-02-17T05:14:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [February 17, 2010, 5:14am UTC](https://discuss.rubyonrails.org/t/back-button/49424/1 "2010-02-17T05:14:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Anthony\_Franco](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/anthony_franco/32/11436_2.png) [@Anthony\_Franco](https://discuss.rubyonrails.org/u/Anthony_Franco)\
**Post date:** [February 17, 2010, 7:57am UTC](https://discuss.rubyonrails.org/t/back-button/49424/2 "2010-02-17T07:57:16Z")

</div>

Try:

button\_to "Back", :back

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [February 17, 2010, 10:35am UTC](https://discuss.rubyonrails.org/t/back-button/49424/3 "2010-02-17T10:35:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [February 17, 2010, 11:02am UTC](https://discuss.rubyonrails.org/t/back-button/49424/4 "2010-02-17T11:02:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Bob8](https://avatars.discourse-cdn.com/v4/letter/b/dbc845/32.png) [@Bob8](https://discuss.rubyonrails.org/u/Bob8)\
**Post date:** [February 17, 2010, 2:42pm UTC](https://discuss.rubyonrails.org/t/back-button/49424/5 "2010-02-17T14:42:05Z")

</div>

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

\<%= link\_to 'Back', request.headers['HTTP\_REFERER'] %\>

Hope this helps,

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [February 17, 2010, 4:57pm UTC](https://discuss.rubyonrails.org/t/back-button/49424/6 "2010-02-17T16:57:29Z")

</div>

Ralph Shnelvar 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,
