lobanovadik
lobanovadik

Reputation: 1088

get controller and action information from url in rails

How can I get information about controller and action names for any (not only current) url, if there is a route rule for this?

For example:

function_i_need('/pages/5') 

returns

{:controller => 'page', :action => 'show', :id => 5}

UPD: Answer found Rails parse url to hash(Routes)

Upvotes: 10

Views: 6386

Answers (1)

Alexander Giraldo
Alexander Giraldo

Reputation: 567

you can do this:

Rails.application.routes.recognize_path "/pages/5"

Upvotes: 18

Related Questions