TomDogg
TomDogg

Reputation: 3940

How do I call a method inside ApplicationHelper from my Model?

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

Upvotes: 2

Views: 838

Answers (1)

Rebitzele
Rebitzele

Reputation: 3282

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.

Upvotes: 3

Related Questions