Use helper within model

3 views
Skip to first unread message

Jeffrey Taylor

unread,
Jan 19, 2018, 9:09:00 AM1/19/18
to pad...@googlegroups.com
I have some code that is common to two models. So I put it a module and put
the module in a file in the model directory and include the module. All
works. I would like to use a method in one of the helpers. Helpers normally
are visible only in controllers and views. How do include it in a model?

The helper method is defined:

module GreenBox
class App
module GreenBoxHelper
def page_number(count)
(count-1)/PAGE_SIZE + 1
end
end

helpers GreenBoxHelper
end
end


If the model common file:
include GreenBox::App::GreenBoxHelper

does not work, the constant GreenBox::App::GreenBoxHelper is not defined.

TIA,
Jeffrey

Adam Daniels

unread,
Jan 19, 2018, 9:17:01 AM1/19/18
to Padrino Framework
Can you try requiring the helper module at the top of your model?

Jeffrey Taylor

unread,
Jan 23, 2018, 9:24:14 AM1/23/18
to Padrino Framework
Yes, that does it.

Thanks,
Jeffrey
Reply all
Reply to author
Forward
0 new messages