Reputation: 2046
Say you have some mailers, but you want a dynamic list of them, how would you go about doing this?
The list is of all the mailer classes within a Rails application that inherit from ActionMailer::Base
.
Upvotes: 2
Views: 1337
Reputation: 19879
> ActionMailer::Base.descendants
=> [Devise::Mailer]
> Dir['app/mailers/*.rb'].each {|f| require File.basename(f, '.rb')}
> ActionMailer::Base.descendants
=> [Devise::Mailer, InternalMailer, MailingListMailer, MessageMailer, UserMailer]
There may well be better ways. Note that if your mailers are somewhere else (or in nested directories) you'd need to modify the Dir glob above.
Upvotes: 6