patternrubyrailsMinor
How and where to define a partial helper module
Viewed 0 times
howhelperwheremoduledefinepartialand
Problem
I want to split my helpers in different modules (and files), but I found some problems which I got around with the following solution:
In particular at the beginning I was looking to have a file
Any Idea or suggestions?
# app/helpers/application_helper.rb
module ApplicationHelper
include ApplicationContainer
# ...
end
# app/helpers/partials/application_container.rb
module ApplicationContainer
# ...
endIn particular at the beginning I was looking to have a file
/app/helpers/_application_container_helper.rb that gave me uninitialized constant ApplicationHelper::ApplicationContainer (and different other errors playing around it), but right now I'm not even sure that makes sense.Any Idea or suggestions?
Solution
Your current solution is fine, in my opinion. The underscore naming-convention used on view-partials doesn't apply for modules, that's why you got the uninitialized constant-error. If you name it
What you have in your code now is a module you can include in other Helper-modules– just as you would a partial in your views.
ApplicationHelper::ApplicationContainer it has to be in a file named application_container.rbWhat you have in your code now is a module you can include in other Helper-modules– just as you would a partial in your views.
Context
StackExchange Code Review Q#2037, answer score: 4
Revisions (0)
No revisions yet.