Home how to check a record if it exists in another database
Reply: 0

how to check a record if it exists in another database

user1551
1#
user1551 Published in December 16, 2017, 10:52 am

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.

edit: as I can see that my question is not so clear. So this is what I am trying to do.

the project should have two type of users student and teacher ( admin ). So the CheckUser will have the userNum for all the teachers. and in the registration, when the user inputs their userNum then the program should check all the records in the CheckUser to see if the user is a teacher ( admin ) or not.

What should I do next ?

Thanks for your time

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.485983 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO