有没有像控制器消毒的东西?

时间:2010-02-22 20:03:56

标签: ruby-on-rails sanitize

控制器是否有消毒功能?

2 个答案:

答案 0 :(得分:4)

via:http://www.adaruby.com/2009/12/16/how-to-use-actionview-helpers-in-your-rails-controller/

我认为Helper类应该是:

class Helper
  include Singleton
  include ActionView::Helpers::TextHelper
end

答案 1 :(得分:3)

我这样做的方式如下:

# in application_controller.rb
def helpers
  Helper.instance
end

class Helper
  include ActionView::Helpers::TextHelper
  include ActionView::Helpers::SanitizeHelper
end

# in your controller
def index 
  @message = "Sanitized #{helpers.sanitize(...)}"
end

这通过扩展内部类来命名控制器中的助手。我希望这有帮助!