开发者

How to design multiple user forms and models

I have a website where people can look up menus from nearby restaurants.

As a restaurant, you can sign up and enter your menu. How should I design the model(s)?

class User < ActiveRecord::Base
  has_one :venue
class Venue < ActiveRecord::Base
  has_many :menus

or should I store 开发者_StackOverflow社区everything (email, password, etc. ) within the venue model?

The next problem is the sign up form. With User and Venue model I have to create multiple models through a single form. Don't think that that is so user friendly.

The last problem: I also want to have "normal" user who can rate restaurants and that stuff. I think this would interfere with the User/Venue Model approach.

What do you think? How would you do it?

Thanks in advance


It sounds like you've kind of answered your first question with your third - if you want to be able to have Users that are not associated with Venues, you'll want to keep these two models separate, or it would interfere with your desire to have different types of users (at least with the ability to do it cleanly). If you keep them separate, some Users can be associated with Venues (restaurant owners) and some can not (regular users). In your case, regular users would have a nil venue.

One note - the difference between has_one and belongs_to isn't always intuitive (at least not to me), you might check out the Rails Active Record Associations guide to make sure you're using the appropriate one.

If there's a lot of functionality that applies only to restaurant owners you might inherit one model from the other to avoid cluttering the base class (i.e. have a User model and a Owner model that inherits from it, or something like that).

As far as the signup form, it sounds like you want to create a single form that allows a restaurant owner to enter the info that will create their User and also their Venue. You can use nested object forms for this - the link refers to Rails 2.3 but I'm using this feature in a Rails 3 project and everything works as advertised.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜