Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Usage:
- # referer? :controller => 'beezies', :action => 'holla', :type => 'popozuda'
- # referer? %r|/\d+/edit|
- def referer?(options)
- referer = request.headers["Referer"]
- return (options.blank? ? true : false) if referer.blank?
- if options.is_a?(Regexp)
- referer =~ options
- else
- # Same logic as current_page? in actionpack/lib/action_view/helpers/url_helper.rb
- url_string = CGI.unescapeHTML(url_for(options))
- # We ignore any extra parameters in the referer if the
- # submitted url doesn't have any either. This lets the function
- # work with things like ?order=asc
- referer = referer.split("?").first unless url_string.index("?")
- if url_string =~ /^\w+:\/\//
- referer == url_string
- else
- referer == "#{request.protocol}#{request.host_with_port}#{url_string}"
- end
- end
- end
Add Comment
Please, Sign In to add comment