I am creating an app for uploading and sharing files between users.
I have User and Files models and have created a third File_Sharing_Relationships model which contains a sharer_id, file_id and shared_with_id columns. I want to be able to create the following methods:
@upload.file_sharing_relationships - lists users that the file is shared with
@user.files_shared_with - lists files that are shared with the user.
@user.files_shared - lists files that the user is sharing with others
@user.share_file_with - creates a sharing relationship
Are there any rails associations, such as ‘polymorphic’ that I could be using to make these relationships?
Any suggestions appreciated. Thanks.
All you need to do is to read Rails Guides and apply all what you learn.
Basically you need to store info about:
So:
You need SharedItem to have:
Then you can get “methods” you specified by writing named scopes like:
or by specifying proper associations: