I am trying to access helper method in my controller using helpers like below:
class MyController < ApplicationController
def index
@foo = 'bar'
helpers.my_helper_method
end
end
Inside Helper method, I am trying to access an instance variable of controller
module MyHelper
def my_helper_method
#some manipulation on foo
@foo.to_i
end
end
But in above scenario @foo is nil. When I call the same method from view, @foo is available. So the instance variable can be passed to helper method only through UI or some other way is there?
Thanks in advance.
UPDATE:
view_context
seems like reasonable solution https://apidock.com/rails/AbstractController/Rendering/view_context