Uninitialized Constant Admin on Heroku - ruby-on-rails

I have a fresh app with only a few gems. Devise being one of them of course. And when I make an Admin model via Devise's Option 1 give here
... and upload to heroku, I am unable to run a db:migrate due to the following error:
rake aborted!
uninitialized constant Admin
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:230:in block in constantize'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:229:ineach'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:229:in constantize'
/app/vendor/bundle/ruby/1.9.1/gems/devise-2.1.2/lib/devise.rb:256:inget'
/app/vendor/bundle/ruby/1.9.1/gems/devise-2.1.2/lib/devise/mapping.rb:77:in to'
/app/vendor/bundle/ruby/1.9.1/gems/devise-2.1.2/lib/devise/mapping.rb:72:inmodules'
/app/vendor/bundle/ruby/1.9.1/gems/devise-2.1.2/lib/devise/mapping.rb:89:in routes'
/app/vendor/bundle/ruby/1.9.1/gems/devise-2.1.2/lib/devise/mapping.rb:156:indefault_used_route'
etc...
Does anyone have any suggestions?

Created another fresh rails app and everything is working now. I believe the problem might have been that I created my Admin model with a capital "A" and some code was looking for an admin model with a lowercase "a"

Related

Ruby on Rails Tutorial by Michael - Chapter -2 Toy App - Puma caught this error: uninitialized constant ApplicationController (NameError)

Puma caught this error: uninitialized constant ApplicationController (NameError)
Hi all,
I am new to Ruby on Rails and I am following Ruby on Rails Tutorial by Michael. I am stuck after creating Micropost. When I go to localhost:3000, the aforementioned error comes up. How should I resolve this?
Next question I have is: aws vs gcp? I am just curious about these two and which should I learn first?
Thank you very much in advance!
When I first added users, I can run rails s. However, after I add Micropost and run rails s, the following error comes up.
I have checked both microposts_controller.rb and users_controller.rb and see if I miss anything. I cannot spot anything.
/home/sum/code/railsbook/toy_app/app/controllers/users_controller.rb:1:in `<main>'
/home/sum/.rvm/gems/ruby-2.6.3/gems/bootsnap-
/home/sum/.rvm/gems/ruby-2.6.3/gems/puma-3.12.1/lib/puma/thread_pool.rb:135:in `block in spawn_thread'
Please check the class name of users_controller.rb, Its similar to file name like UsersController.
otherwise maybe its rails issue: check this out https://github.com/rails/rails/issues/35749

Cannot load database model in rails c production

aliyun Elastic Compute Service
app_danci#iZ2ze599ua4y0nvsppbmjhZ:~/myproject$ rails c -e production
Running via Spring preloader in process 13978
Loading production environment (Rails 5.1.4)
2.3.1 :001 > u = User.first
NameError: uninitialized constant User
from (irb):1
2.3.1 :002 > User.all
NameError: uninitialized constant User
from (irb):2
Why can I not see the model User?
You're probably missing something. I think you have a migration for a users table. Have you run rails db:migrate? If so, maybe you have just the table but you have not defined the class User?
class User < ApplicationRecord
end
or maybe is your class User defined inside a module?
The common error, one can make is not using appropriate nested Namespaces. If your models are defined under a namespace please use it in your console too. It can be called by using a qualifying names such as ::Namespace::Model. It is highly unlikely that rails console loads fine and can't seem to call the Rails Model. Hope this helps.

$ rails g pundit:install errors 'const_get' : wrong constant name Admin? (Name Error) while attempting to generate default policy library

New to ROR working through a tutorial attempting to generate a default policy file for my application with the pundit:install.
$ rails g pundit:install generates the following error:
.rvm/gems/ruby-2.2.0/gems/devise-3.4.1/lib/devise/models.rb:88:in `const_get': wrong constant name Admin? (NameError)
I also tried captilizing pundit with the following command:
$ rails g Pundit:install , but it generates the same error:
The given error message doesn't yet point to Pundit as being the problem:
.rvm/gems/ruby-2.2.0/gems/devise-3.4.1/lib/devise/models.rb:88:
in `const_get': wrong constant name Admin? (NameError)
Is there a longer stack trace for the error message? If yes, please add it to the question.
Also search your app's files for Admin? (with a capital 'A'). See that Admin? is mentioned in the error message wrong constant name Admin?.
(At a guess, somewhere in the app, Admin? is written where it should not be. Perhaps it needs to be removed or replaced with small 'a': admin?. Or replaced with Admin without the question mark.)

How to install Active Admin somewhere other than "/admin"?

I'm trying to add Active Admin to a Rails app that already has a bespoke CMS and Admin model living at path /admin, and which already uses the devise gem, but when I try to run rails g active_admin:install followed by rake db:migrate, I get this error:
/usr/local/rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeadmin-0.6.0/lib/active_admin/namespace.rb:227:in `eval': Admin is not a module (TypeError)
from /usr/local/rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeadmin-0.6.0/lib/active_admin/namespace.rb:227:in `eval'
from /usr/local/rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeadmin-0.6.0/lib/active_admin/namespace.rb:227:in `register_module'
from /usr/local/rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeadmin-0.6.0/lib/active_admin/namespace.rb:41:in `initialize'
from /usr/local/rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeadmin-0.6.0/lib/active_admin/application.rb:142:in `new'
from /usr/local/rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeadmin-0.6.0/lib/active_admin/application.rb:142:in `namespace'
from /usr/local/rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeadmin-0.6.0/lib/active_admin/application.rb:128:in `register'
from /usr/local/rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeadmin-0.6.0/lib/active_admin.rb:79:in `register'
I know it's possible to set a default namespace in the initializer that the install creates, but I wondered if there was a way to pass a default namespace of my choosing in as an option with the install command?
Thanks in advance!
OK - finally figured it out:
I kept the active_admin.rb initializer created when I ran the Active Admin install command the first time, and deleted every other file that it had created. I then added this line to the initializer:
config.default_namespace = :my_custom_admin_namespace
and ran the install again, skipping the Devise user class (as suggested here), like so:
rails g active_admin:install --skip-users
I ran my migrations, and I was then able to visit myapp.co.uk/my_custom_admin_namespace. At first I did see an error about an unknown method regarding authenticating users (which makes sense given I skipped creating the user class), so I commented out the following two lines in the initializer:
config.authentication_method = :authenticate_admin_user!
config.current_user_method = :current_admin_user
and now I can see the dashboard. It's not an ideal setup yet since it's lacking the user class and any authentication, but it's a start.

Rails 3: Rails console not opening

Suddenly, I'm not able to open the console or anything else related to the ActiveRecord in my app.
I always get this error:
~/Code/act(master) $ rails c
/Users/donald/.rvm/gems/ruby-1.9.2-rc2/gems/activerecord-3.0.3/lib/active_record/connection_adapters/sqlite_adapter.rb:295:in `table_structure': Could not find table 'wsps' (ActiveRecord::StatementInvalid)
from /Users/donald/.rvm/gems/ruby-1.9.2-rc2/gems/activerecord-3.0.3/lib/active_record/connection_adapters/sqlite_adapter.rb:186:in `columns'
from /Users/donald/.rvm/gems/ruby-1.9.2-rc2/gems/activerecord-3.0.3/lib/active_record/base.rb:679:in `columns'
from /Users/donald/.rvm/gems/ruby-1.9.2-rc2/gems/activerecord-3.0.3/lib/active_record/base.rb:692:in `column_names'
from /Users/donald/.rvm/gems/ruby-1.9.2-rc2/gems/validates_lengths_from_database-0.1.2/lib/validates_lengths_from_database.rb:20:in `validates_lengths_from_database'
I've tried this solution https://rails.lighthouseapp.com/projects/8994/tickets/99-sqlite-connection-failing with no effect.
What am I doing wrong here? Even when I checkout version who used to work from github I get the same error.
Regards,
Thanks
Try
rake db:migrate
I am assuming either you started in a new folder, or you added a new migration. The error states clearly that the table wsps cannot be found.

Resources