how can i use a helper in different views

Hans picture Hans · May 20, 2011 · Viewed 22.5k times · Source

i am using refinery cms at the moment. I created an engine and with it some helpers in app/helpers/admin/. now i would like to use those helpers in my frontend view (ie. app/views/myapp/index) as well. but i can not...undefined methode error. what do i have to do short of copying the whole thing to app/helpers/? the helper looks like this

module Admin
    module myHelper
        def somefunc
        end
    end
end

so is it possible to use somefunc outside of the Admin module?

Answer

bobics picture bobics · Aug 12, 2012

The "Rails way" to include a helper from a non-standard path in a view is to use the .helper method within your controller.

class MyController < ApplicationController
    helper Admin::MyHelper
    ...
end

http://apidock.com/rails/AbstractController/Helpers/ClassMethods/helper