Get Controller Name Or Action Name Of Previous Page In Rails

Posted By Weston Ganger

It can be helpful to know what controller or actions name the previous request had. This is a nice clean method to get that information.

Rails.application.routes.recognize_path(request.referrer) #=> {:controller => "posts", :action => "show"}

prev[:action] #=> "show"
prev = Rails.application.routes.recognize_path(request.referrer)
prev[:controller] #=> "posts"

Related External Links:

Article Topic:Software Development - Ruby / Rails

Date:October 15, 2015