Newy
Newy

Reputation: 40107

Planning for 2 Types of Users on a Rails App

What is the best way to architect a Rails app to handle two distinct classes of users? For a marketplace there'll be Buyers and Sellers. There will be overlapping functionality in editing the profiles and such, but most the funcitonality will be distinct. Is the approach in the following post a good way to do it? I'm hoping to use RESTful Authentication.

http://www.imarichardson.com/2007/06/30/using-2-instances-of-restful-authentication-with-different-models/

Upvotes: 2

Views: 278

Answers (3)

Toby Hede
Toby Hede

Reputation: 37133

You can also look at using a more fully-fledged authorisation plugin like:

Such a system provides you with a complete DSL for providing access to your application.

Upvotes: 0

cwninja
cwninja

Reputation: 9768

I'd keep the authentication separate from the user info and details. Have a UserAuth object for auth and then a polymorphic association to a User record. A Buyer and a Seller are then just subclasses of User, as long as you refer to them and not the UserAuth objects all the rails helpers (render @user to render either a _buyer or a _seller partial etc.) should work just fine.

Both buyer and seller can delegate generic stuff back down to the UserAuth instance.

Just a thought.

Upvotes: 1

Jon Hester
Jon Hester

Reputation: 199

You could just use one instance of RESTful Authentication and add a column to the Users table that would say which class a user was a part of. Then you can show certain links/pages only to users that match a particular class.

I use this method to have different user roles (admin, editor, regular user, etc.).

Upvotes: 0

Related Questions