I’ve created Haml helper and put it as file in path app/helpers/haml_helper.rb
module Haml::Helpers
def build_segment(files)
files.each do |f|
if f[:dir] == nil
haml_tag :li do
haml_tag :a, :class=>"file", :href=>f[:name] do
f[:name]
end
end
else
haml_tag :li do
haml_tag :a, :class=>"folder", :href=>f[:name] do
f[:name]
end
end
haml_tag :ul do
build_segment(f[:dir])
end
end
end
end
end
But then I’ve got an error:
LoadError in SourceFilesController#index
Expected /home/megas/Work/read_the_code/app/helpers/haml_helper.rb
to define HamlHelper
SourceFilesController#index is an action which going to use this custom helper.
How to add custom haml helper to the project?
So, when you have haml_helper.rb, it expects it to define HamlHelper …. but you wanted Haml::Helper. So:
This is the same when you have namespaced controllers. Admin::CustomersController is at app/controllers/admin/customers_controller.rb