I know that I can define methods in e.g. the application controller and
make them available to the helpers using helper_method(), but how can I
make them available in the models?
I have for example the following method, that I want to be able to call
from any model I wish…
I know that I can define methods in e.g. the application controller and
make them available to the helpers using helper_method(), but how can I
make them available in the models?
You can’t, or at least not without hacking it. If you are following the
MVC design pattern, your model shouldn’t know anything about the view or
controller. This allows you to use a model in other environments, such
as from a cron activated script. You want your business logic in the
model, and application logic in the controller/view.
So you can’t get to the controller object from the model. But if you
have an algorithm you want to use in both places, you can put it in a
library module and include it in both places.