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 

Want me to help develop your next project or application?

Contact Us

Specializing in Ruby-on-Rails, Javascript, Multi-Platform Electron Desktop Apps and Hybrid Cordova Mobile Apps.

Recommended Posts