I know I can use request.referrer to get the full referrer URL in Rails, but is there a way to just get the controller name from the URL?
I want to see if the URL of http://myurl.com/profiles/2 includes “profiles”
I know I can use a regex to do it but I wondered if there was a better way.
Inside the controller, you have the method
controller_namewhich returns you only the name. In your case, it would return “profiles”.You may also use
params[:controller]which returns the same string.