Search code examples
ruby-on-railsreview

Rails: How do I keep different new/updated records before they're approved?


I am now working on non-standart (for me at least) problem. I am to create system where any user profile change (or account creation) is to be approved as well as its child records.

For example -

  1. User is crested/changes something >>
  2. Status is changed to "Review" >>
  3. Changes not applied yet >>
  4. Admin reviews stuff >>
  5. Approves >>
  6. Changes applied.

When child object is created/updated - we get all the same process.

I was thinking of different ideas (as storing changes in serialized hash, using versions with paper_trail), but everything I come up with is very messy.

Just wondering if someone did similar stuff - what is the cleanest way to get this working?


Solution

  • I will use a mirror table 'UsersChanges' with 1 to 1 relationship to 'User' and the same id.

    If any user have a relationship with 'UsersChanges' you know that the user has changes to be commited (only need a count).

    And if you want to know their change you have to look by the same id to the other table ('UsersChanges').

    And when changes are approved you only need to copy the data and remove 'UsersChanges' row.

    Using hash with data can be more complex, you have to validate you hash and you will be using 'magical strings' for creating a model.

    Hope it helps