Forum: Ruby on Rails "Recognizing" a controller and action from an URL?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ivan V. (Guest)
on 2007-07-25 00:20
Hi,

I'm trying to find something in ActionController::Routing that can help
me find out which controller and action are responsible for a certain
URL.

So far it seems something like this might be an answer:

request, response = ActionController::CgiRequest.new(cgi,
session_options),
  ActionController::CgiResponse.new(cgi)

controller = ActionController::Routing::Routes.recognize(request)

But how would I build the cgi and session_options parameters?

Is there a simpler way?

Thanks.

- Ivan V.
Ivan V. (Guest)
on 2007-07-25 00:32
Ivan V. wrote:
> Hi,
>
> I'm trying to find something in ActionController::Routing that can help
> me find out which controller and action are responsible for a certain
> URL.
>
> So far it seems something like this might be an answer:
>
> request, response = ActionController::CgiRequest.new(cgi,
> session_options),
>   ActionController::CgiResponse.new(cgi)
>
> controller = ActionController::Routing::Routes.recognize(request)
>
> But how would I build the cgi and session_options parameters?
>
> Is there a simpler way?
>
> Thanks.
>
> - Ivan V.

Yeah, much simpler:

ActionController::Routing::Routes.recognize_path(path)

That returns a hash with the controller and action names.

This will do wonders for my authentication system!

I hope this is useful to somebody else besides me.

- Ivan V.

PS: NetBeans 6 debugging rocks. Try it if you haven't already.
This topic is locked and can not be replied to.