Is it possible to add a project if a custom model already exists?

We already created a user model at the beginning of the project, but now (a few transitions later) we would like to use a gem. Is it possible to add a project if a custom model and table already exist? That is, is it possible to change what has already been done, or do we need to start all over again?

+5
source share
3 answers

Cavert Coder, but:

(Note that this does not tolerate ": lockable" because it didn’t bother me when I wrote it . Now it includes: lockable because MattSlay cared more than me. :). In addition, you need to transfer user passwords to encrypted passwords. Finally, this may not work for you. Unfortunately.)

class AddDevise < ActiveRecord::Migration
  def self.up
    null    = false
    default = ""

    add_column :users, :encrypted_password, :string, :null => null, :default => default, :limit => 128
    add_column :users, :password_salt, :string
    add_column :users, :authentication_token, :string
    add_column :users, :confirmation_token,   :string
    add_column :users, :confirmed_at,         :datetime
    add_column :users, :confirmation_sent_at, :datetime
    add_column :users, :reset_password_token, :string
    add_column :users, :remember_token,      :string
    add_column :users, :remember_created_at, :datetime
    add_column :users, :sign_in_count,      :integer, :default => 0
    add_column :users, :current_sign_in_at, :datetime
    add_column :users, :last_sign_in_at,    :datetime
    add_column :users, :current_sign_in_ip, :string
    add_column :users, :last_sign_in_ip,    :string

    #:lockable fields contributed by MattSlay
    add_column :users, :failed_attempts, :integer, :default => 0
    add_column :users, :unlock_token,   :string
    add_column :users, :locked_at, :datetime

  end

  def self.down
    remove_column :users, :encrypted_password
    remove_column :users, :password_salt
    remove_column :users, :authentication_token
    remove_column :users, :confirmation_token
    remove_column :users, :confirmed_at
    remove_column :users, :confirmation_sent_at
    remove_column :users, :reset_password_token
    remove_column :users, :remember_token
    remove_column :users, :remember_created_at
    remove_column :users, :sign_in_count
    remove_column :users, :current_sign_in_at
    remove_column :users, :last_sign_in_at
    remove_column :users, :current_sign_in_ip
    remove_column :users, :last_sign_in_ip
    remove_column :users, :failed_attempts
    remove_column :users, :unlock_token
    remove_column :users, :locked_at
  end
end
+4
source

In addition to the list that Aquarion provided, I think I found three fields that you need if you want to implement the option: lockable in the User model:

add_column :users, :failed_attempts, :integer, :default => 0
add_column :users, :unlock_token,   :string
add_column :users, :locked_at, :datetime
+3
source

. , Devise . . schema.rb , .

Alternatively, you can read the source through the source and find out where things like “database_authenticatable” are defined. You have to start here .

0
source

All Articles