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?
It's possible, although not very common, to use helper methods from controller actions. Before Rails 5, you had to include the helper module. In newer versions, you can use helpers in your controller with the helpers (plural) object.
A Helper method is used to perform a particular repetitive task common across multiple classes. This keeps us from repeating the same piece of code in different classes again and again. And then in the view code, you call the helper method and pass it to the user as an argument.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With