Posted By

vanne on 04/18/07


Tagged

rails ruby


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

webstic


Use helpers in controllers or models


 / Published in: Ruby
 

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

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

  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"

Report this snippet  

You need to login to post a comment.