rails helpers location
I ma开发者_运维问答de a simple helper with one function and put it in the relevant controller_helper and I noticed that the function is valid from the whole application views.
Why is that? shouldn't the helper be valid only to his controller?
The process is the following:
If you're in a view belonging to controller foo
and you call a helper called my_helper
:
if defined in
foo
's helper, it's executed from hereif not defined in
foo
's helper but defined in another helper, saybar
, it's executed from thereif not in
foo
nor in anybar
, it's checked inapplication_helper
. If it doesn't exist here, an error is raised.
That would make sense, but it's not the complete story. I have a controller MainController
and a controller AlsoController
, and defined a helper with the same name wherefrom
in each of the helper modules ie MainHelper
and AlsoHelper
. But if I try to make use of wherefrom
in the also
view, it uses the helper defined in MainHelper
instead of the one in AlsoHelper
.
精彩评论