Use helpers in controllers or models

引用
http://snipplr.com/view/2505/use-helpers-in-controllers-or-models


his is an easy to use any helpers that rails provides in any other place besides views and view helpers
Plain TextExpand

  
      # create a new file inside lib/ and call it helpers.rb
   
      # paste the following:
   
       
   
      def help
   
      Helper.instance
   
      end
   
       
   
      class Helper
   
      include Singleton
  
      # look inside ActionView::Helpers to include any other helpers that you might need
  
      include ActionView::Helpers::DateHelper
  
      include ActionView::Helpers::TextHelper
  
      end
  
       
  
      # then in any model or controller:
  
      require 'lib/helpers'
  
       
  
      # to use:
  
      # help.name_of_helper
  
      # EX: help.pluralize 10, "person"


你可能感兴趣的:(Rails)