In order for users to register in the system, the administrator must grant them a code that is registered in the DB in the 'codes' table, then when the user is filling out the registration form, they must enter said code in the "code" field. , excuse the redundancy, and when saving the data I need the system to validate that the code entered by the user coincides with one already registered in the 'codes' table, otherwise it will not be possible to register.
I could do it by querying the DB in the controller before saving the record, the thing is that I'm using Devise for user authentication and registration, and I can't think of anything else... Can someone guide me?
You can create a controller that inherits from Devise and add your logic to it; for instance:
And then you just have to update your routes so that Devise uses the controller you just created: