Phillip:
Because you're defining MY_ACCOUNT_METHODS as a constant in a module
it will not have access to the template methods.
Named routes methods are injected into ActionController::Base, and
ActionView::Base, and
since the Helper methods are usually called from those contexts, you
can call the named routes
methods from within the helper methods, but not within the helper
declaration itself, if that makes sense.
so if you define a method in your helper:
def some_method
person_path
end
"person_path" doesn't need to be recognized until it is called by the
ActionView or ActionController class that has included this helper
module. That
ActionView or ActionController class will have also included the named
routes methods so, it will know what it means.
So everything works as expected.
But if you call it from within the actual definition of the module, as
you have done here, nobody has told it yet about the named routes, so
it freezes up.
You can solve the problem in several ways. One way is to instead of
declaring the :url for each menu in your constant, just declare a
symbol for the
method to call later:
MY_ACCOUNT_MENU = {
:id => 'my_account_menu',
:title => 'My Account',
:children => [
{
:title => 'Home',
:url_method => :person_path
}
]
}
Then in generate_menu, to get the url, call
self.send(menu[:url_method])
And in that case "self" will be the ActionView or ActionController
object doing the calling, and it will know what "person_path" means.
Hope that helps.