# How to do sharable content the Rails way

**URL:** <https://www.ruby-forum.com/t/how-to-do-sharable-content-the-rails-way/84181>\
**Category:** Rails\
**Created:** [February 2, 2007, 2:31am UTC](https://www.ruby-forum.com/t/how-to-do-sharable-content-the-rails-way/84181 "2007-02-02T02:31:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeteSalty](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bc79bd/32.png) [@PeteSalty](https://www.ruby-forum.com/u/PeteSalty)\
**Post date:** [February 2, 2007, 2:31am UTC](https://www.ruby-forum.com/t/how-to-do-sharable-content-the-rails-way/84181/1 "2007-02-02T02:31:39Z")

</div>

I have a little issue about how to structure a database for a Rails  
app that includes sharing.  
The application is for song writers and musicians and helps then  
collaborate on musical pieces.

Essentially there are a couple of parts

There are ‘owners’ who create ‘songbooks’ and ‘songs’.  
Each ‘songbook’ can contains many ‘songs’ and ‘songs’ must belong to  
one ‘songbook’, although they can be copied as new versions to other  
‘songbooks’  
Both ‘songsbooks’ and ‘songs’ can be shared with other ‘owners’ to  
various degrees.

I can elect to make a ‘songbook’ or ‘song’ shared with other users  
in the following ways (I’d need to know their email address or  
username):  
read-only (can only read, can’t contribute)  
read-write (can read and edit existing songs but can’t add new  
ones)  
read-write-add (can read, edit and contribute new songs to the  
songbook - this doesn’t apply to a single shared song, just songbooks)

I can also make ‘songs’ and ‘songbooks’ public:  
public-read (anyone, even users who aren’t subscribed to the  
service or aren’t logged in can read)  
public-full (anyone, even users who aren’t subscribed to the  
service or aren’t logged in can read and edit songs - although they  
can’t add songs)

Now, I’m a little new to Rails and I know how I’d go about this in C#  
(i.e. by writing lots and lots of code) but Rails has so many  
mechanisms that I am unaware of I was wondering if there was already  
some way or doing this, or if not all of it then maybe 90%  
Problem is I’m not sure if I need to structure my tables a certain  
way, or if there are fields I need to include, or what. I’m not even  
sure where to start. I’ve searched this forum and Google and whole  
bunch of places but I now have more questions than answers.

I guess the way I’d do it is something like:

Tables (roughly):

owners  
id - integer  
email - varchar(255)  
username - varchar(20)  
password…

songbooks  
id - integer  
name - varchar(50)  
owner\_id - integer

songs  
id - integer  
name - varchar(50)  
songbook\_id - integer

songbook\_shares  
owner\_id - integer  
songbook\_id - integer  
type - integer

song\_shares  
owner\_id - integer  
song\_id - integer  
type - integer

Models:

class Owner \< ActiveRecord::Base

```
has_many :songbooks
has_many :songbook_shares
has_many :song_shares

etc...

```

end

class Songbook \< ActiveRecord::Base

```
belongs_to :owner

etc...

```

end

class Song \< ActiveRecord::Base

```
belongs_to :songbook

etc...

```

end

But this is where I get stuck. I suspect my original table ideas are  
wrong, but I’m just not sure how to proceed in the Rails way.

If anyone has tackled something like this before and could point me in  
the right direction I’d really appreciate it.

Dale
