How to include the mail_to helper inside of a controller

Hello, in my controller I need to format a json object using
simple_format, which is why I need to include several helpers.

So far I have the following in my controller:

      include ApplicationHelper
      include ActionView::Helpers::TextHelper
      include ActionView::Helpers::TagHelper

This works great for simple_format, problem is when the
comment.content has a email address, rails trys to do a mailto link
which breaks, showing the following error in the logs: "NoMethodError
(undefined method `mail_to' for...."

Any ideas on how to add it in? I tried adding include
ActionView::Helpers::UrlHelper but that did not work. I get this error
when I include the UrlHelper: "undefined local variable or method
`controller"

Thank you

Coincidentally, I had to resort to using number_to_currency in a
controller the other day (okay, I didn't *have* to - I decided it
easier to do it that way for the task I had to do :slight_smile:

A quick Google for "number_to_currency controller" (now I'm giving
away my Google-fu?!) gleaned this:
http://lojic.com/blog/2007/07/27/using-helpers-inside-controllers-in-ruby-on-rails/

..and for my quick and "I feel dirty" use, I settled for the solution:
Object.new.extend(ActionView::Helpers::NumberHelper).number_to_currency(my_number)

HTH

Pavling, thanks for the repy! I’ve been stuck on this bug all morning…

So I’m trying to understand how to get this working based on your suggestion.

Here’s the flow:

My controller calls html_format(comment.content) which is inside of the application helper

html_format, then calls simple_format. This only errors when there is an email in comment.content. If there is a link or just plain text it works just fine.

Given that, can you help me understand your suggestion on how to resolve? Thank you!

Ok turns out it’s not simple_format, I forgot that I was using auto_link. Removing auto_link prevent the error. So now I need to figure out what I need to include in the controller to user auto_link