Closed nightfall708 closed 3 years ago
do you have a file app/models/application_record.rb ?
PS : coding as root is very dangerous.
Also: does it work without Devise, and fails only with it?
The error doesn't seem to mention or point to anything related to Devise apparently, so I'm inclined to think it's unrelated to the library. If you are able to reproduce just with Devise and can send some script or app reproducing the problem, I'll be happy to take a better look. Thanks.
@seuros I don't have that file..
@carlosantoniodasilva the user.rb file was generated after creating the devise migration (rails g devise User
) so it's related...
@talshr devise triggers the Rails / Active Record generator to create the model if it doesn't exist: https://github.com/heartcombo/devise/blob/c82e4cf47b02002b2fd7ca31d441cf1043fc634c/lib/generators/active_record/devise_generator.rb#L25
And that should create a model inheriting from ApplicationRecord
(instead of the "old" way from ActiveRecord::Base
): https://github.com/rails/rails/blob/255b5ff9af57f9b54dee7ec884b12a1ad16f0321/activerecord/lib/rails/generators/active_record/model/model_generator.rb#L57
If you don't have ApplicationRecord
in your app its probably because it's been upgraded over time and never created one, so other models are likely inheriting from ActiveRecord::Base
... You can either just change the user model to inherit from it too, or create an ApplicationRecord
as that's expected to exist going forward. You can do that via the active_record:application_record
generator. Hope that helps.
Yes already solved this way thank you!
Thanks. This helped me too. I had the same error because I've added "devise_for :users" in config/routes.rb before running $ rails generate devise User
Upon upgrading from Rails 6 to 7 and Ruby 2.5.6 to 3.0.0, I encountered the same issue while setting up the project. , when running rails c, I received the following error:
/home/pranshu_007/edn_server/app/models/configuration.rb:17:in <top (required)>': uninitialized constant ApplicationRecord (NameError) from /home/pranshu_007/.rvm/gems/ruby-3.0.0/gems/zeitwerk-2.6.13/lib/zeitwerk/kernel.rb:34:in
require'
from /home/pranshu_007/.rvm/gems/ruby-3.0.0/gems/zeitwerk-2.6.13/lib/zeitwerk/kernel.rb:34:in require' from /home/pranshu_007/edn_server/config/initializers/carrierwave.rb:6:in
<top (required)>'
from /home/pranshu_007/.rvm/gems/ruby-3.0.0/gems/railties-7.1.0/lib/rails/engine.rb:683:in load' from /home/pranshu_007/.rvm/gems/ruby-3.0.0/gems/railties-7.1.0/lib/rails/engine.rb:683:in
block in load_config_initializer'
from /home/pranshu_007/.rvm/gems/ruby-3.0.0/gems/activesupport-7.1.0/lib/active_support/notifications.rb:208:in instrument' from /home/pranshu_007/.rvm/gems/ruby-3.0.0/gems/railties-7.1.0/lib/rails/engine.rb:682:in
load_config_initializer'
from /home/pranshu_007/.rvm/gems/ruby-3.0.0/gems/railties-7.1.0/lib/rails/engine.rb:636:in block (2 levels) in <class:Engine>' from /home/pranshu_007/.rvm/gems/ruby-3.0.0/gems/railties-7.1.0/lib/rails/engine.rb:635:in
each'
from /home/pranshu_007/.rvm/gems/ruby-3.0.0/gems/railties-7.1.0/lib/rails/engine.rb:635:in block in <class:Engine>' from /home/pranshu_007/.rvm/gems/ruby-3.0.0/gems/railties-7.1.0/lib/rails/initializable.rb:32:in
instance_exec'
from /home/pranshu_007/.rvm/gems/ruby-3.0.0/gems/railties-7.1.0/lib/rails/initializable.rb:32:in run' from /home/pranshu_007/.rvm/gems/ruby-3.0.0/gems/railties-7.1.0/lib/rails/initializable.rb:61:in
block in run_initializers'
from /home/pranshu_007/.rbenv/versions/3.0.0/lib/ruby/3.0.0/tsort.rb:228:in block in tsort_each' from /home/pranshu_007/.rbenv/versions/3.0.0/lib/ruby/3.0.0/tsort.rb:350:in
block (2 levels) in each_strongly_connected_component'
from /home/pranshu_007/.rbenv/versions/3.0.0/lib/ruby/3.0.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
Pre-check
Environment
Current behavior
I've installed devise and generated the migration. However I'm encountering this error when trying to migrate:
NameError: uninitialized constant ApplicationRecord /root/myapp/app/models/user.rb:1:in `<top (required)>'
Not sure why, because ApplicationRecord should be supported in rails 6.