Referencing outside controller from inside namespace
Yesterday, I came across a case where I needed to refer to an outside controller’s action from a namespaced view.
It is actually a form, which submits data. So, I needed to use post
method.
I updated the route accordingly. Changed the form’s url option, refreshed!
But no! that didn’t work!
Wouldn’t work
I used something like this, let :admin
be the namespace.
In the form, I used upload_document_path
which didn’t work. Neither this one -
The solution
The solution to this problem was very simple one, but is also tricky.
I had to add a small ‘/’ before the controller name. So the changed form_helper line becomes -
So, to route from inside a namespaced path to outer controller, we should use /controller_name
instead of just controller_name
.
Hope, this will help someone.