From 074fe35b8a9c82e22a2c8b7559df158ad513981a Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Mon, 8 Oct 2007 03:30:29 +0000 Subject: 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 --- actionpack/lib/action_view/helpers/url_helper.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'actionpack/lib') 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 # * :confirm => 'question?' -- 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 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 -- cgit v1.2.3