HiveBrain v1.2.0
Get Started
← Back to all entries
patternrubyrailsMinor

How and where to define a partial helper module

Submitted by: @import:stackexchange-codereview··
0
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:

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

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 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.

Context

StackExchange Code Review Q#2037, answer score: 4

Revisions (0)

No revisions yet.