Closed eneagoe closed 6 days ago
Hi @eneagoe , I've encountered a similar error. In the error, there is the following statement.
from ~/webapp/config/initializers/devise_mailers.rb:1:in `<main>'
Actually, isn't the definition like this?
class Devise::Mailer < Devise.parent_mailer.constantize
include Devise::Mailers::Helpers
def confirmation_instructions(record, token, opts = {})
@token = token
devise_mail(record, :confirmation_instructions, opts)
end
# and another override for mailer etc.
end
And then, you should these override in custom mailer.
Please refer to the documentation ( https://github.com/heartcombo/devise/wiki/How-To:-Use-custom-mailer ) as well.
So you should remove config/initializers/devise_mailers.rb
.
config/application.rb
is like this,
Devise.setup do |config|
...
config.mailer = "MyMailer"
config.parent_mailer = "ApplicationMailer"
end
Thank you @ebihara-tomonari but the link you mention is referring to using a custom mailer, not a parent mailer.
This seems to be a class loading issue - the defined parent mailer class is not loaded so Devise::Mailer
crashes because it can't find its base class.
@eneagoe Yeah, I know that.
But, your devise_mailers.rb
probably customize like custom mailer, and use parent_mailer in the end.
And your error occured config/initializers/devise_mailers.rb
, not ~config/application.rb
~ config/initializers/devise.rb
.
That why config.parent_mailer = "ApplicationMailer"
in ~config/application.rb
~ config/initializers/devise.rb
is no problem.
So I think, if you remove config/initializers/devise_mailers.rb
, rails command don't occur error at least.
You should check config/initializers/devise_mailers.rb
.
And, if you customize Devise::Mailer
in devise_mailers.rb
, you should customize with custom mailer.
I'm so sorry 🙇
not config/application.rb
, config/initializers/devise.rb
is correct!
Thank you, I think I figured out the issue indeed, you pointed me in the right direction - the culprit was the devise_mailers.rb
: if I move that custom setup into the config.mailer
class the app correctly starts, and parent_mailer
is also correctly configured.
I'm going to close this one, thank you again for the help!
Environment
Current behavior
Setting up the
parent_mailer
options withprevents the application from starting up - there's a class loading issue, apparently:
Trying to get around this issue by defining the class in
config/initializers/devise.rb
with something likewill start the app correctly, but it won't work as expected - none of the before actions defined in
app/mailers/application_mailer.rb
will apply.Expected behavior
Setting up
parent_mailer
should at the very least not crash the booting process.