Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using sanitize within a Rails controller

I'm trying to call sanitize within a controller. Here's what I tried:

class FooController < ApplicationController   include ActionView::Helpers::SanitizeHelper   # ... end 

However, I'm getting this error:

undefined method `white_list_sanitizer' for FooController:Class 

I searched around and people recommended switching the include line to include ActionView::Helpers, but that results in this error:

undefined method `url_for' for nil:NilClass 

What's the correct way to call sanitize? I'm using Rails 2.3.5.

like image 653
pmc255 Avatar asked Oct 21 '10 09:10

pmc255


1 Answers

you can use this ActionController::Base.helpers inside action method:

class SiteController < ApplicationController   def index     render :text => ActionController::Base.helpers.sanitize('<b>bold</b>')   end end 

Hope this helps

like image 54
JCorcuera Avatar answered Oct 11 '22 08:10

JCorcuera