If I want to have functions to be called inside controllers, where should I put them?
if you want it to be local to a controller then all you need to do is to add it to the controller you wish to use.
private
def myfunction
function code.....
end
to all controllers you can put it inside the application controller, because all controlers are sub classed.
protected
def myfunction
function code.....
end
If you want access in your views then you can create a helper
def myfunction
function code...
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