Closed jondkinney closed 3 months ago
Checking for connected?
proved problematic 👇
[1] pry(main)> User.organizers
NoMethodError: undefined method `organizers' for User (call 'User.connection' to establish a connection):Class
from /Users/jon/.rvm/gems/ruby-2.5.1@headway_rails_template/gems/activerecord-5.2.1/lib/active_record/dynamic_matchers.rb:22:in `method_missing'
However, I was able to simply rescue the ::ActiveRecord::NoDatabaseError
and things work again. Hopefully we can get this fixed at a higher level, or a better spot in the gem though.
See here for more discussion on what's changed with 5.2 and the after_initialize
hook https://github.com/rails/rails/issues/32870
I'll be testing this more, but wanted to get some early feedback.
I know the gem isn't super popular, but I'm surprised no one else has run into this yet. It'd happen for starting a new project or when running
rails db:drop
(which works without this fix) andrails db:create
(which doesn't work without this fix) because it's trying to connect to the database before one exists while also trying to create it.