aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2007-10-08 03:30:29 +0000
committerMichael Koziarski <michael@koziarski.com>2007-10-08 03:30:29 +0000
commit074fe35b8a9c82e22a2c8b7559df158ad513981a (patch)
treeeb480da4e854e6bfe071c2d6ea083cec3c1768bb /actionpack/lib
parent85c86f09997fff1f07f5d58ecf69780d597e292c (diff)
downloadrails-074fe35b8a9c82e22a2c8b7559df158ad513981a.tar.gz
rails-074fe35b8a9c82e22a2c8b7559df158ad513981a.tar.bz2
rails-074fe35b8a9c82e22a2c8b7559df158ad513981a.zip
Add link_to :back which uses your referrer with a fallback to a javascript link. #7366 [eventualbuddha, tarmo]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7791 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_view/helpers/url_helper.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb
index 70d3ddd403..77201de1d6 100644
--- a/actionpack/lib/action_view/helpers/url_helper.rb
+++ b/actionpack/lib/action_view/helpers/url_helper.rb
@@ -86,8 +86,9 @@ module ActionView
# of +options+. See the valid options in the documentation for
# url_for. It's also possible to pass a string instead
# of an options hash to get a link tag that uses the value of the string as the
- # href for the link. If nil is passed as a name, the link itself will become
- # the name.
+ # href for the link, or use +:back+ to link to the referrer - a JavaScript back
+ # link will be used in place of a referrer if none exists. If nil is passed as
+ # a name, the link itself will become the name.
#
# ==== Options
# * <tt>:confirm => 'question?'</tt> -- This will add a JavaScript confirm
@@ -134,7 +135,14 @@ module ActionView
# var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method');
# m.setAttribute('value', 'delete'); f.appendChild(m);f.submit(); };return false;">Delete Image</a>
def link_to(name, options = {}, html_options = nil)
- url = options.is_a?(String) ? options : self.url_for(options)
+ url = case options
+ when String
+ options
+ when :back
+ @controller.request.env["HTTP_REFERER"] || 'javascript:history.back()'
+ else
+ self.url_for(options)
+ end
if html_options
html_options = html_options.stringify_keys