I have a custom module I would like to access in my mail helper, but i can’t figure out how to include it.
My custom module lib/workday.rb:
module Workday
def next_workday(date = Date.today)
...
end
...
end
That i try to use in my MailHelper:
module MailHelper
include Workday
def next_workday(date = Date.today)
Workday.next_workday(date)
end
...
end
When trying to use the helper i get this:
undefined method `next_workday' for Workday:Module
/www/xxx/app/helpers/mail_helper.rb:4:in `next_workday'
When manually including the module in the console it works fine directly and through the helper:
> include Workday
=> Object
> Workday.next_workday
=> Fri, 04 Jan 2013
> helpers.next_workday
=> Fri, 04 Jan 2013
If you include a
Modulethe methods will be accessible as instance methods. If you try to access thenext_workdaymethod directly through the module, the method must be defined as a “class method” (withself.).Your
MailHelpershould work if you use:There is no need to define the
next_workdaymethod inMailHelpersince it just delegates toWorkday#next_workdayanyways. If you include yourMailHelperinto a class you can then access the method withnext_workday