I’ve been trying to find an answer to this question via Google, but am
having a terrible time coming up with the correct search terms.
I would like to use the routing helpers (person_path, new_person_path,
etc) in files other than controllers or views, specifically helpers
and/or custom files in lib/. Is this possible?
My specific scenario involves a dynamically generated sidebar menu. I
have the menu broken down into array and hash constants, each one
representing a particular submenu the user may or may not have access
to. An example looks like
MY_ACCOUNT_MENU = {
:id => ‘my_account_menu’,
:title => ‘My Account’,
:children => [
{
:title => ‘Home’,
:url => person_path
},
{
:title => ‘Profile’,
:url => edit_person_path
},
{
:title => ‘Change Password’,
:url => change_password_path
},
{
:title => ‘Additional Emails’,
:url => ‘/person/additional_emails’
},
{
:title => ‘Notification Test’,
:url => ‘/person/notification_test’
}
]
}
As you can see here, I’m hoping to use the named routes instead of
hard-coding the paths. But this does not work as I get
undefined method `person_path’
errors. I have tried this in a module in lib/ and in a helper in
helpers/.
Peace,
Phillip