While I realize you are supposed to use a helper inside a view, I need a helper in my controller as I'm building a JSON object to return.
It goes a little like this:
def xxxxx
@comments = Array.new
@c_comments.each do |comment|
@comments << {
:id => comment.id,
:content => html_format(comment.content)
}
end
render :json => @comments
end
How can I access my html_format
helper?
You can use
helpers.<helper>
in Rails 5+ (or ActionController::Base.helpers.<helper>
)view_context.<helper>
(Rails 4 & 3) (WARNING: this instantiates a new view instance per call)@template.<helper>
(Rails 2) singleton.helper
include
the helper in the controller (WARNING: will make all helper methods into controller actions)