Check out example codes for "create if not exists rails". It will help you in understanding the concepts better.

Code Example 1

Contact.where(survey_id: survey,voter_id: voter).first_or_create

Learn ReactJs, React Native from akashmittal.com