jeudi 30 novembre 2017

how to check a record if it exists in another database

ok so I am using devise and I created devise user, In a new migrate I added two cloumns to the users table as follows:

   add_column :users, :userNum, :integer
   add_column :users, :isAdmin, :boolean, :default => false

and I created a new model called checkUser which created a migration which has a table as shown here:

class CreateCheckUsers < ActiveRecord::Migration
  def change
    create_table :check_users do |t|
      t.integer :userNum
      t.boolean :isAdmin, :default => false

      t.timestamps null: false
    end
  end
end 

Then I inserted a record into the checkUser using the following command from the console:

CheckUser.create(userNum:525252)

Now I want to check when the user enters the userNumber into the form. The checking should be as follows: If userNumber entered by user is already in checkUser table then set the field isAdmin in the users table to true, otherwise set it to false.

What should I do next ?

Thanks for your time

Aucun commentaire:

Enregistrer un commentaire