Use helpers in controllers or models


/ Published in: Ruby
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. # create a new file inside lib/ and call it helpers.rb
  2. # paste the following:
  3.  
  4. def help
  5. Helper.instance
  6. end
  7.  
  8. class Helper
  9. include Singleton
  10. # look inside ActionView::Helpers to include any other helpers that you might need
  11. include ActionView::Helpers::DateHelper
  12. include ActionView::Helpers::TextHelper
  13. end
  14.  
  15. # then in any model or controller:
  16. require 'lib/helpers'
  17.  
  18. # to use:
  19. # help.name_of_helper
  20. # EX: help.pluralize 10, "person"

URL: http://snippets.dzone.com/posts/show/1799

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.