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

后端 未结 6 911
伪装坚强ぢ
伪装坚强ぢ 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:10

    This works better for me:

    Simple:

    ApplicationController.helpers.my_helper_method
    

    Advance:

    class HelperProxy < ActionView::Base
      include ApplicationController.master_helper_module
    
      def current_user
        #let helpers act like we're a guest
        nil
      end       
    
      def self.instance
        @instance ||= new
      end
    end
    

    Source: http://makandracards.com/makandra/1307-how-to-use-helper-methods-inside-a-model

提交回复
热议问题