How to add sharing to individual entries - Rails 4 -


i have application user can create multiple entries.

i user able share individual entry user.

i'm struggling wrap head around how structure this.

the goal allow user share individual entry, , entry viewed in other users entry feed. don't want "shared user" able make changes, view shared entry.

i'm semi new rails, , it's seems specific enough i'm struggling find answer searching.

let me know how else can clarify question.

any appreciated. thanks.

so user can have many entries , can have shared_entries.

database tables

entries       shared_contents       users -id           -id                   -id -content      -user_id              -username -user_id      -entry_id 

user.rb

has_many :entries has_many :shared_contents has_many :shared_entries, through: :shared_contents, source: :entry 

entry.rb

belongs_to :user has_many :shared_contents has_many :users_who_shared, through: :shared_contents, source: :user 

shared_content.rb

belongs_to :user belongs_to :entry 

this way can share entry this:

entry = entry.first current_user.shared_entries << entry  

displaying it:

controller

@shareds = sharedcontent.inclues(:entries, :users).order(created_at: :desc).limit(20) 

view

@shareds.each |shared|   shared.entry.content   shared.user.username # user shared   shared.entry.user.username # user created entry 

this code not tested, may have errors. hope help, or @ least give idea.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -