Forum: Ruby on Rails modelling data to specify user access

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jason (Guest)
on 2006-05-11 04:30
Hello, this is my second Rails app, and the first one I did had simple
data mapping.  This time I am building a site for a photographer, and
they want to upload photos, and create galleries that only certain
clients can log in and have access to.  There will be multiple
galleries, and the access to them will vary depending on how the admin
assigns it to each client.  There is also a porftolio that everyone
coming to the site can see.  So I was thinking to have one master Images
table that holds all the images, and divide it out into portfolio and
galleries.

I am sitting down mapping the data right now, but I am not sure how to
handle this.  How many tables to I need and how do I map them together?
So far I have these tables:

Users
*ID
*username
*password

Images
*ID
*image_name
*path_to_image
*path_to_thumbnail

Galleries
*ID
*gallery_name

and then I'm not sure about:

Gallery_Names?
User_Access?

I'd appreciate help if anyone has had experience with this before...

Jason
Josh C. (Guest)
on 2006-05-11 04:39
(Received via mailing list)
The most basic way I see it is

gallery
has_many :pictures
has_many :users

So you just create the gallery and add a gallery_id to the pictures
table and to the users table.

Josh
Jason (Guest)
on 2006-05-11 04:51
Josh C. wrote:
> The most basic way I see it is
>
> gallery
> has_many :pictures
> has_many :users
>
> So you just create the gallery and add a gallery_id to the pictures
> table and to the users table.
>
> Josh

Thanks, that part makes sense.  I think though it might be more
complicated?  Each user can have access to more than one gallery, and
each image can be in multiple galleries.  Like if the client wants to
present the same image in a different gallery taylored for each client.
Josh C. (Guest)
on 2006-05-11 05:00
(Received via mailing list)
On 5/10/06, Jason <removed_email_address@domain.invalid> wrote:
> Thanks, that part makes sense.  I think though it might be more
> complicated?  Each user can have access to more than one gallery, and
> each image can be in multiple galleries.  Like if the client wants to
> present the same image in a different gallery taylored for each client.

Then just change the has_many to has_and_belongs_to_many then create a
gallaries_users and gallaries_pictures table.

Josh
This topic is locked and can not be replied to.