Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NameError: uninitialized constant User

I am using the rails-devise apps with Rails composer. Everything seems fine until I try to interact with the model in the console. I tried the commands:

rails console
User.all

And I get the following error from the console:

NameError: uninitialized constant User
from (irb):2
from /Users/msarr/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5.1/lib/rails/commands/console.rb:110:in `start'
from /Users/msarr/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5.1/lib/rails/commands/console.rb:9:in `start'
from /Users/msarr/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5.1/lib/rails/commands/commands_tasks.rb:68:in `console'
from /Users/msarr/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/msarr/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5.1/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/msarr/Desktop/deployment/YouServe/bin/rails:9:in `<top (required)>'
from /Users/msarr/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/msarr/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'

Here is my Gemfile:

  source 'https://rubygems.org'
  ruby '2.2.1'
  gem 'rails', '4.2.5.1'
  gem 'sass-rails', '~> 5.0'
  gem 'uglifier', '>= 1.3.0'
  gem 'coffee-rails', '~> 4.1.0'
  gem 'jquery-rails'
  gem 'turbolinks'
  gem 'jbuilder', '~> 2.0'
  gem 'carrierwave'
  gem 'mini_magick'
  gem 'fog'                  
  gem 'administrate'
  gem 'devise'
  gem 'devise_invitable'
  gem 'foundation-rails', '~> 5.5'
  gem 'high_voltage'
  gem 'simple_form'

 group :development, :test do
  gem 'byebug'
  gem 'sqlite3'
end
group :development do
  gem 'web-console', '~> 2.0'
  gem 'spring'
  gem 'better_errors'
  gem 'hub', :require=>nil
  gem 'quiet_assets'
  gem 'rails_layout'
end

group :production do
 gem 'pg'
 gem 'rails_12factor'
 gem 'unicorn'
end
like image 857
codigomonstruo Avatar asked Feb 25 '16 01:02

codigomonstruo


2 Answers

Just restarting the spring loader.

spring stop

then run rails c It's working fine

like image 84
dhina2525 Avatar answered Nov 15 '22 03:11

dhina2525


What does the architecture of your project look like? If you have any modules or namespacing wrapped around your models (API or v1, for example), then you would have to call them with the namespace, i.e. V1::User.all.

like image 28
Scott Schupbach Avatar answered Nov 15 '22 04:11

Scott Schupbach