Get Controller Name Or Action Name Of Previous Page In Rails

Posted by Weston Ganger on October 15, 2015

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:

Posted in Rails and Tagged with rails 

Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts