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 - Rails

Date:October 15, 2015

Recommended Posts



Send Me A Message

I would love to get in touch and talk about your next project. Feel free to send a message and I will get back to you shortly.

Get Connected