本文介绍了在Rails控制器中使用sanitize的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在控制器中调用 sanitize
。这里是我尝试:
I'm trying to call sanitize
within a controller. Here's what I tried:
class FooController < ApplicationController
include ActionView::Helpers::SanitizeHelper
# ...
end
但是,我收到此错误:
undefined method `white_list_sanitizer' for FooController:Class
我搜索过,人们建议切换include行以包含 ActionView :: Helpers
,但会导致此错误:
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
调用 sanitize
的正确方法是什么?我使用Rails 2.3.5。
What's the correct way to call sanitize
? I'm using Rails 2.3.5.
推荐答案
你可以使用 ActionController :: Base.helpers
内部操作方法:
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
希望这有助于
这篇关于在Rails控制器中使用sanitize的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!