Forum: Ruby on Rails How to do sharable content the Rails way

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
9ae68be4f6aff5c6aa7a0eb7087251e9?d=identicon&s=25 PeteSalty (Guest)
on 2007-02-02 02:31
(Received via mailing list)
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
  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
    read-only (can only read, can't contribute)
    read-write (can read and edit existing songs but can't add new
    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):

    id - integer
    email - varchar(255)
    username - varchar(20)

    id - integer
    name - varchar(50)
    owner_id - integer

    id - integer
    name - varchar(50)
    songbook_id - integer

    owner_id - integer
    songbook_id - integer
    type - integer

    owner_id - integer
    song_id - integer
    type - integer


  class Owner < ActiveRecord::Base

    has_many :songbooks
    has_many :songbook_shares
    has_many :song_shares



  class Songbook < ActiveRecord::Base

    belongs_to :owner



  class Song < ActiveRecord::Base

    belongs_to :songbook



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.

This topic is locked and can not be replied to.