本文介绍了在 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

我四处搜索,人们建议将包含行切换为包含 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.

推荐答案

你可以在 action 方法中使用这个 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-02 02:34