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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Michael Pavling
2011-Mar-01 21:41 UTC
Re: How to include the mail_to helper inside of a controller
On 1 March 2011 18:41, Inverted <brett-CBMGfOASXPM8hbakYQNKQ0EOCMrvLtNR@public.gmane.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-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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Inverted
2011-Mar-01 22:29 UTC
Re: How to include the mail_to helper inside of a controller
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! -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Inverted
2011-Mar-01 22:42 UTC
Re: How to include the mail_to helper inside of a controller
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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.