question about looking up classes

  • Thread starter Ball, Donald A Jr (Library)
  • Start date
B

Ball, Donald A Jr (Library)

Hi folks. I've run into some behavior in a rails app that I don't
understand. I don't think it's specific to rails, but feel free to
redirect me if I'm off-topic.

I wanted to manually invoke the rails router path recognition in one of
my controller classes. When I tried the naive solution:

def index
...
result_params =3D
ActionController::Routing::Routes.recognize_path(uri.path)
...
end

I got a NameError:

uninitialized constant
ActionWebService::Dispatcher::ActionController::Routing

I google codesearched for anyone else doing this sort of thing and
stumbled across the solution of putting the call into a metaclass
method:

class << self
def recognize_path(path)
ActionController::Routing::Routes.recognize_path(path)
end
end

def index
...
result_params =3D self.class.recognize_path(uri.path)
...
end

I'm quite puzzled as to why the class lookup works in the context of a
metaclass method, but doesn't in the context of an instance method (or a
normal class method, for that matter), but am not sure if I'm running
into rails metamagic or my own incomplete understanding of ruby. Any
tips for me?

- donald
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top