Created
May 21, 2014 12:23
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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