I’m trying to create a custom helper like this:
# app/controllers/my_controller.rb
class MyController < ApplicationController
helper :my
def index
puts foo
end
end
# app/helpers/my_helper.rb
module MyHelper
def foo
"Hello"
end
end
But, I got the following error:
undefined local variable or method `foo' for #<MyController:0x20e01d0>
What am I missing ?
Helpers are accessed from the views, not the controllers. so if you try to put the following inside your index template it should work:
If you do want to access something from the controller, then you should use the include syntax instead of helper, but do not name it like a helper module in that case.