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
on 2011-03-01 20:53
on 2011-03-01 22:42
On 1 March 2011 18:41, Inverted <firstname.lastname@example.org> wrote: > Hello, in my controller I need to format a json object using > simple_format, which is why I need to include several helpers. > > Any ideas on how to add it in? 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 :-) 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-ins... ..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
on 2011-03-01 23:30
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!
on 2011-03-01 23:43
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