domain for sale $5k usd (negotiable). Em@il me t0: alex at israstage dot com

My Git activity

02 September 2007

link_to_back helper

It will take referer, @params and redirect you back to same page you been before.

Useful then sorting search results, paging, editing different objects via same _form...
This is code for helper file, i prefer application helper.

def link_to_back (description = "Back")
referer = request.env["HTTP_REFERER"]
return false if !referer
getIt = request.env["REQUEST_URI"].split("?")[1]
if getIt.nil?
getIt = ""
getIt = "?" + getIt if !getIt.match(/\?/)
link_to description, referer + getIt

then just do:
<%= link_to_back %> or
<%= link_to_back "Cancel" %>

1 comment: