# 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.

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top