# Assistance in how to Query an Record and Update the same record using Ruby on Rails

**URL:** <https://www.ruby-forum.com/t/assistance-in-how-to-query-an-record-and-update-the-same-record-using-ruby-on-rails/132319>\
**Category:** Rails\
**Created:** [March 19, 2008, 4:55am UTC](https://www.ruby-forum.com/t/assistance-in-how-to-query-an-record-and-update-the-same-record-using-ruby-on-rails/132319 "2008-03-19T04:55:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mervyn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b38774/32.png) [@mervyn](https://www.ruby-forum.com/u/mervyn)\
**Post date:** [March 19, 2008, 4:55am UTC](https://www.ruby-forum.com/t/assistance-in-how-to-query-an-record-and-update-the-same-record-using-ruby-on-rails/132319/1 "2008-03-19T04:55:37Z")

</div>

I am a newbie to RoR  
I have this problem which I will represent in psuedocode - it  
describes the allocation of a randomisation number to a patient  
participating in a clinical trial at a particular hospital site.

1. User (Doctor) logs on on with username: JBLOGGS
2. Based on his username - system returns him a dropdownlist of  
SITE\_ID’s that he has access to (previously set up in a database table  
eg. USER\_SITES (SITE\_ID, USERNAME) -
3. User selects a site available to him. eg 90001
4. User enters INITIALS of patient
5. User press SUBMITT button
6. The system will get the next available RANDOMISATION record  
(retrieved in ascending order of the RAND\_SEQ number) which has a  
unique RAND\_NUMBER and DRUG\_KIT\_NUMBER.
7. The inputed INITIALS will be updated in RANDOMISATION record,  
similarly the CREATED\_BY and CREATED\_DATE fields
8. System returns a screen containing USERNAME, SITE\_ID, INITIALS,  
RAND\_NUMBER, DRUG\_KIT\_NUMBER to the User - this information will be  
recorded in patient notes on another system.

Assumptions:

1. If the SITE\_ID and INITIALS field if not null - then the  
RANDOMISATION record is used already and not available.

TABLE STRUCTURES:

USER\_SITES (SITE\_ID, USERNAME);

RANDOMISATION (RAND\_SEQ, RAND\_NUMBER, DRUG\_KIT\_NUMBER, SITE\_ID,  
INITIALS, CREATED\_BY, CREATED\_DATE);

If anyone can assist me in anyway - I would be most grateful.

Kind Regards from DownUnder (New Zealand)  
Mervyn
