Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6246007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:36:41+00:00 2026-05-24T12:36:41+00:00

I am creating an app for uploading and sharing files between users. I have

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:36:42+00:00Added an answer on May 24, 2026 at 12:36 pm

    All you need to do is to read Rails Guides and apply all what you learn.

    Basically you need to store info about:

    • user who created a “sharing”
    • user or group or whatever is a target of a sharing action
    • resource that is being shared

    So:

    class SharedItem < ActiveRecord::Base
          belongs_to :sharable, :polymorphic => true #this is user, please think of better name than "sharable"...
          belongs_to :resource, :polymorphic => true #can be your file
          belongs_to :user
    end
    

    You need SharedItem to have:

    user_id: integer, sharable_id: integer, sharable_type: string, resource_id: integer, resource_type: string
    

    Then you can get “methods” you specified by writing named scopes like:

    named_scope :for_user, lambda {|user| {:conditions => {:user_id => user.id} }}
    

    or by specifying proper associations:

    class File < ActiveRecord::Base
      has_many :shared_items, :as => :resource, :dependent => :destroy
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a django app with some model for uploading files. I need to
i am creating app which would download and save files, than user could use
I am creating an app which will have a question in a UILabel and
I'm creating an app that will have a fair amount of users. Everytime someone
I am creating an app in which on clicking on button user can send
I am creating an app that will require authentication which I have already gotten
We are creating an app that uses modules which are dynamically loaded into the
I'm creating and app that will rely on a database, and I have all
I am creating an app that is having a UIWebView which contains an advert.
I'm in the process of creating an app. I'd like to have a pared

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.