06 Apr

Rails: find controller for a path

Huh, seems simple to do :p, but I’ve been seeking for a while to find the answer and dig into rails code to find a simple method to retrieve the controller of a given path (could be useful to build a navigation). There it is:

ActionController::Routing::Routes.recognize_path(path)[:controller]
tags: rails (32) ruby (22) routes (1) path (1) controller (2)