Guest User

Untitled

a guest
May 24th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. # Usage:
  2. # referer? :controller => 'beezies', :action => 'holla', :type => 'popozuda'
  3. # referer? %r|/\d+/edit|
  4.  
  5. def referer?(options)
  6. referer = request.headers["Referer"]
  7. return (options.blank? ? true : false) if referer.blank?
  8.  
  9. if options.is_a?(Regexp)
  10. referer =~ options
  11. else
  12. # Same logic as current_page? in actionpack/lib/action_view/helpers/url_helper.rb
  13. url_string = CGI.unescapeHTML(url_for(options))
  14. # We ignore any extra parameters in the referer if the
  15. # submitted url doesn't have any either. This lets the function
  16. # work with things like ?order=asc
  17. referer = referer.split("?").first unless url_string.index("?")
  18.  
  19. if url_string =~ /^\w+:\/\//
  20. referer == url_string
  21. else
  22. referer == "#{request.protocol}#{request.host_with_port}#{url_string}"
  23. end
  24. end
  25. end
Add Comment
Please, Sign In to add comment