Pregunta

# application_helper.rb

def do_some_stuff
   ...
end


# my_model.rb

def my_model_method
   # I want to call the method "do_some_stuff" here, how exactly?
end

Obviously, I can't just call do_some_stuff, since it would tell me that the model does not have this method.

¿Fue útil?

Solución

You can accomplish this by adding the following line to your model file:

include ActionView::Helpers

Now, you may want to reconsider placing your helper method somewhere else (e.g. the model, or a mixin module), but use the above line to do what you've asked for.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top