6
\$\begingroup\$

I want to split my helpers in different modules (and files), but I found some problems which I got around with the following solution:

# app/helpers/application_helper.rb
module ApplicationHelper
  include ApplicationContainer
  # ...
end

# app/helpers/partials/application_container.rb
module ApplicationContainer
  # ...
end

In 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?

\$\endgroup\$
4
\$\begingroup\$

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 ApplicationHelper::ApplicationContainer it has to be in a file named application_container.rb

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.