I have a controller, I want to create a helper for this controller that I can use without including it. I tried creating a helper with the same name as the controller like so
class Cars::EnginesController < ApplicationController
def start_engine
check_fuel
end
end
and the helper that i created was
module Cars::EnginesHelper
def check_fuel
logger.debug("cheking fuel")
end
end
and the error that i got was
undefined local variable or method `check_fuel' for #<Cars::EnginesController:0x1160e8c80>
is there any conventions that i am missing out?
If you really want to use helper methods in controller, you can treat your helper as regular Ruby module (which it is, honestly) and use include
:
class Cars::EnginesController < ApplicationController
include Cars::EnginesHelper
# ...
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With