开发者

Is there anything like sanitize for controllers?

开发者 https://www.devze.com 2022-12-21 02:30 出处:网络
Is there anything like sanitize for开发者_如何学JAVA controllers?via: http://www.adaruby.com/2009/12/16/how-to-use-actionview-helpers-in-your-rails-controller/

Is there anything like sanitize for开发者_如何学JAVA controllers?


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

I think the Helper class should be:

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


The way I do this is as follows:

# 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

This namespaces your helpers in the controller, kind of, by extending an inner class. I hope this helps!

0

精彩评论

暂无评论...
验证码 换一张
取 消