Using helpers in model: how do I include helper dependencies?

后端 未结 6 892
伪装坚强ぢ
伪装坚强ぢ 2020-11-27 13:37

I\'m writing a model that handles user input from a text area. Following the advice from http://blog.caboo.se/articles/2008/8/25/sanitize-your-users-html-input, I\'m cleani

6条回答
  •  离开以前
    2020-11-27 14:14

    Just change the first line as follows :

    include ActionView::Helpers
    

    that will make it works.

    UPDATE: For Rails 3 use:

    ActionController::Base.helpers.sanitize(str)
    

    Credit goes to lornc's answer

提交回复
热议问题