Skip to content

Instantly share code, notes, and snippets.

@kakra
Created May 21, 2014 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kakra/f55320360ffad0b618c1 to your computer and use it in GitHub Desktop.
Save kakra/f55320360ffad0b618c1 to your computer and use it in GitHub Desktop.
Snippet of a Rails helper proxy to make helpers available from anywhere without polluting namespace
# use helpers from models or any part of your app (you shouldn't do that, however...)
# ... put in config/initializers
#
# class MyModel < ActiveRecord::Base
# def some_attribute
# HelperProxy.instance.number_format some_value, precision: 4
# end
# end
class HelperProxy
include Rails.application.helpers
include ActionView::Helpers::NumberHelper
def self.instance
@@instance ||= new
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment