Search code examples
ruby-on-railsrubyrefinerycms

how can i use a helper in different views


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?


Solution

  • In your application_helper.rb:

    module ApplicationHelper
      include Admin::MyHelper
    end
    

    This will import those helper methods into the ApplicationHelper, thus making them available in your views. You could do this in any of your helpers really.