I am pretty new but am trying to learn through doing. I have a Profile model and Vendor model which are related as follows:
class Profile < ActiveRecord::Base
has_one :vendor, dependent: :destroy
end
class Vendor < ActiveRecord::Base
belongs_to :profile
end
The Profile model has a field called :verified_vendor which is a bool that is default false for all profiles. The Vendor model for now has only one field but we will be adding more later, that field is :reference_account_num. Once we do some in-house financials logic, I have set up a route in our app where the admin will go in and select the Profile, select to verify the profile as a vendor, then enter the vendor reference account number they created in the financial system. The application then creates a vendor row and updates the profile to verified as true. I want to make sure that I validate that a row must be created when the flag is flipped. I have looked at doing this through an observer, but is that the right path? Since the flag is in the Profile it seems I can update the :reference_account_num field and it breaks my business logic because the vendor information doesn't have to be created.
- Admin selects a profile and selects verify as vendor
- Admin enters the financial reference number
- The transaction creates a vendor row and updates the profile :verified_vendor to true