rails: Mailer classes do not load until console is reloaded (reload! is called)
Steps to reproduce
Create a mailer using generator or manually. Add methods to this class. Start rails console and try to use these methods from this class on the console. Example
class ReportMailer < ApplicationMailer
def daily_report(args)
#do stuff
end
end
Expected behavior
Method should have worked.
Actual behavior
NameError (uninitialized constant ReportMailer)
my mailer is called ReportMailer
System configuration
Rails 6.0.1 Ruby 2.5.0
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 6
- Comments: 38 (23 by maintainers)
Commits related to this issue
- Stop EventedFileUpdateChecker's listener only When an `EventedFileUpdateChecker` instance detects a watched directory that previously did not exist, it calls `shutdown!` and then `boot!` to reinitial... — committed to jonathanhefner/rails by jonathanhefner 4 years ago
- Stop EventedFileUpdateChecker's listener only When an `EventedFileUpdateChecker` instance detects a watched directory that previously did not exist, it calls `shutdown!` and then `boot!` to reinitial... — committed to Shopify/rails by jonathanhefner 4 years ago
This issue occurs because all listeners are stopped (but not all restarted) when a previously non-existent watched directory is created, e.g.
test/mailers/previews
. I intend to fix this, but guard/listen#476 needs to be resolved first, which I am working on.I have same problem too. try
spring stop
. It works for me.Interesting, thanks!
I have some busy days, but will eventually dig into this.
I also had this issue and
spring stop
works.@alea12 could you please try disabling Spring?
ah d’oh! well if helpful I can delete these comments ! thanks for your help!
Yup, this is happening to me too. @fxn / @alea12 comment on disabling Spring was the workaround for me as well. I’ve been using generators for my models that past few days and the models are working as expected. This does seem more specific to ActionMailers for some reason.
I’m on Rails 6.0.2
Hey! Heads up, I have been able to reproduce something weird that seems probably related (irrelevant output cut):
If you then do something as simple as
The constant
Foo
is not found either:I have added some traces and the problem is that, for some reason, Spring does not notice the project has changed and it does not trigger a reload.
If you stop Spring, or perform that process with Spring disabled, this does not happen.
It does seem related to mailers, because if you try to do the same steps with an innocent
FooJob
is found as usual. Same with models, etc. That is, Spring reloads.Excellent, weird though. Let’s close to keep issues low (so to speak, haha), but please reopen if you find a way to reproduce.