My goal is to keep in application_helper only the methods that I use in the templates, otherwise my application_helper gets too long.
My problem relies in the suffix Helper:
This works
# app/helpers
module ApplicationHelper
include ApplicationLayout
end
# app/helpers/layouts
module ApplicationLayout
def my_helper
puts 'my_helper!'
end
end
This doesn’t
# app/helpers
module ApplicationHelper
include ApplicationLayoutHelper
end
# app/helpers/layouts
module ApplicationLayoutHelper
def my_helper
puts 'my_helper!'
end
end
The error is:
Expected app/helpers/layouts/application_layout_helper.rb to define Layouts::ApplicationLayoutHelper
So I nest it and I get:
Routing Error undefined method `sub' for nil:NilClass
Actually I’d like to implement (give your opinion) app/helpers/layouts/application_helper.rb but it gives the same error, so for simplicity I stated this case.
Any suggestion on how to extract helper methods for layouts? Is there any convention over configuration I could use?
Thank you
Well, I tried what you expect and it’s pretty straight:
in
helpers/layouts/application_layout_helper.rbin
helpers/application_helper.rbAd in my view I directly do:
I still don’t really understand what you’ll do with these methods.