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
Just restarting the spring loader.
spring stop
then run rails c
It's working fine
Be sure to include gem 'devise'
in your Gemfile and run bundle
also you will need to run the following
rails generate devise:install
rails generate devise User
rake db:migrate
Now you should be able to access User.all
in your rails c
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, ie V1::User.all
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.