0
I am trying to put an entity I already had in my project as Sign in to login and etc, I used the following commands
add in Gemfile the line gem 'devise'
in the terminal executed:
rails generate devise:install
rails generate devise User
after doing so it generated a file for change in the database:
#20160114174028_add_devise_to_users.rb
class AddDeviseToUsers < ActiveRecord::Migration
def self.up
change_table(:users) do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
# Uncomment below if timestamps were not included in your original model.
# t.timestamps null: false
end
add_index :users, :email, unique: true
add_index :users, :reset_password_token, unique: true
# add_index :users, :confirmation_token, unique: true
# add_index :users, :unlock_token, unique: true
end
def self.down
# By default, we don't want to make any assumption about how to roll back a migration when your
# model already existed. Please edit below which fields you would like to remove in this migration.
raise ActiveRecord::IrreversibleMigration
end
end
and altered my Routes and my model, being that in Routes he add the line devise_for :users
, however before I was with my controller inside an api folder so it was like this my Routes.br
#routes.rb
Rails.application.routes.draw do
namespace :api do
devise_for :users
resources :schedules, except: [:new, :edit]
# resources :users, except: [:new, :edit]
end
end
and my model he added a lines getting like this:
#user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_many :schedules
end
the problem is that when I went to give the command rake db:migrate
gave the following exit:
== 20160113192834 CreateSchedules: migrating ==================================
-- create_table(:schedules)
-> 0.0022s
== 20160113192834 CreateSchedules: migrated (0.0027s) =========================
rake aborted!
NameError: uninitialized constant CreateUsers
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:261:in `const_get'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:261:in `block in constantize'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:259:in `each'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:259:in `inject'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:259:in `constantize'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activesupport-4.2.4/lib/active_support/core_ext/string/inflections.rb:66:in `constantize'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activerecord-4.2.4/lib/active_record/migration.rb:775:in `load_migration'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activerecord-4.2.4/lib/active_record/migration.rb:770:in `migration'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activerecord-4.2.4/lib/active_record/migration.rb:765:in `disable_ddl_transaction'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activerecord-4.2.4/lib/active_record/migration.rb:1048:in `use_transaction?'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activerecord-4.2.4/lib/active_record/migration.rb:958:in `rescue in block in migrate'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activerecord-4.2.4/lib/active_record/migration.rb:955:in `block in migrate'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activerecord-4.2.4/lib/active_record/migration.rb:952:in `each'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activerecord-4.2.4/lib/active_record/migration.rb:952:in `migrate'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activerecord-4.2.4/lib/active_record/migration.rb:820:in `up'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activerecord-4.2.4/lib/active_record/migration.rb:798:in `migrate'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activerecord-4.2.4/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
NameError: uninitialized constant CreateUsers
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:261:in `const_get'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:261:in `block in constantize'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:259:in `each'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:259:in `inject'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:259:in `constantize'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activesupport-4.2.4/lib/active_support/core_ext/string/inflections.rb:66:in `constantize'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activerecord-4.2.4/lib/active_record/migration.rb:775:in `load_migration'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activerecord-4.2.4/lib/active_record/migration.rb:770:in `migration'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activerecord-4.2.4/lib/active_record/migration.rb:765:in `disable_ddl_transaction'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activerecord-4.2.4/lib/active_record/migration.rb:1048:in `use_transaction?'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activerecord-4.2.4/lib/active_record/migration.rb:1040:in `ddl_transaction'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activerecord-4.2.4/lib/active_record/migration.rb:994:in `execute_migration_in_transaction'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activerecord-4.2.4/lib/active_record/migration.rb:956:in `block in migrate'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activerecord-4.2.4/lib/active_record/migration.rb:952:in `each'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activerecord-4.2.4/lib/active_record/migration.rb:952:in `migrate'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activerecord-4.2.4/lib/active_record/migration.rb:820:in `up'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activerecord-4.2.4/lib/active_record/migration.rb:798:in `migrate'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/home/vagrant/.rvm/gems/ruby-2.2.0@rails_4_2_jet2go/gems/activerecord-4.2.4/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
A similar mistake had already happened to me and I just corrected giving a rake db:drop
, but this time it didn’t work.
This has happened to someone else when it comes to generating Visa, and someone better knows how to make it work and why it happens?