Is it possible to include / use Application Helper methods inside of an config/initializers/browser_blocker.rb
?
I am using the browser gem to detect and b
This is one way to do it:
# lib/browser_util.rb
module BrowserUtil
def self.supported?(browser)
# your code ...
end
end
and wrap that from ApplicationHelper for use in views
module ApplicationHelper
def is_browser_supported?
BrowserUtil.supported?(browser)
end
end
in middleware
Rails.configuration.middleware.use Browser::Middleware do
unless BrowserUtil.supported?(browser)
redirect_to :controller => 'error', :action => 'browser-upgrade-required'
end
end
UPDATE: it does not need to be in a separate module (BrowserUtil)
module ApplicationHelper
def self.foo
"FOO"
end
def foo
ApplicationHelper.foo
end
end
in middleware use
ApplicationHelper.foo
in views it would use the included method
foo