I am relatively new to Ruby on Rails. What I am trying to accomplish has not been covered by the tutorials I found and I am unsure how to research the best approach, so I am hoping for some pointers from the community. Thank you!
This is what I am going for:
-
There are Schools and Cities. Both have Users that will have respective roles.
-
The users are supposed to upload photos. These need some meta information stored with them, most importantly the photo credits. I am assuming best practice would therefore be to have a Photo model that stores the actual file link as a string, and the credits as a string, and then I would refer to the photo_id from the School or City. Photo would simultaneously "belongs_to" both School and City, which shouldn't be an issue according to this: can model "belong_to" two other models and have a nested relationship?
-
Users of both roles can create Features (in the sense of "Featured Post"). Features will always need a Photo.
-
When users update their School/City or create/update a Feature, they should be able to choose from their respective School's/City's Photos, OR upload a new one; ideally in the same form. Users should never be able to choose from photos that users of other Schools or Cities uploaded.
Questions:
- Is what I describe in the second point above the best practice approach or should I handle this business logic differently?
- If Photo potentially
belongs_toSchool or City, how do I validate that any given Photo can only belong to one? (It's not covered in the answer linked above.) - How can I use the School and City update forms to incorporate the creation of Photos when these are freshly uploaded? (I understand how to use CarrierWave with the goal of storing an image:string in the record, but this is a step more complicated.)
Any help is appreciated!
