How to effectively set approved, non approved and drafts for a Rails model?

I have a model in my app called photos. Any user can upload photos. When uploaded at first, I store them in a temporary field names tempfile. Then the admin can review them and approve them. If approved the approved field will be true and the photo will be uploaded the s3. The photo will be saved in the file field and the tempfile will be removed. The submitted field in the database will be set to true. If the upload fail, it will be marked in the database. If the photo is rejected, the user can resubmit them.

  • So, in the normal view i need to show approved and non failed uploads
  • If a user edit a photo it should be unapproved and submit until the admin approve them
  • In the resubmit menu I have to show unapproved, unsubmitted photos
  • If user resubmit, the submit field will be set to true

By the looks of it I have to use a lot of database fields and it gets complex. Is there a way to handle this better? A way to save draft and save unapproved separately? How to do this effectively?

PS : This is a bit different and complex scenario than the one I posted earlier. A different app with more complex needs than just a simple draft.

I think you may need some kind of state machine. There is an enum-like field in Rails that might hold your state http://api.rubyonrails.org/classes/ActiveRecord/Enum.html. You can build your own setters and transitions in a model concern, or you can find a gem for that, there’s a bunch of those https://www.ruby-toolbox.com/categories/state_machines.html.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.