开发者

Multi - User Multi Environment

开发者 https://www.devze.com 2023-02-11 03:08 出处:网络
I\'m looking to create an app, where each user can create their own... \"Universe\" in a way, with the amount of items and names that makes sense to them, etc.

I'm looking to create an app, where each user can create their own... "Universe" in a way, with the amount of items and names that makes sense to them, etc.

I've never done this before, so far I've had the typical cases where you have users and admins, but they're both looking essentially at the same thing. Here each user will have a separate environment.

Obviously a user should not be able to see someone else开发者_开发技巧's environment.

Can someone please point me to the right direction on this subject? Maybe some useful gems or resources I could use to get started?

Any advice is welcome!


I'd start with using a plugin for authentication, e.g. AuthLogic or Devise are two popular examples.

Both of these let you define a User class.

Then, when you are showing the user their stuff in their environment, you can make sure you only show them their own stuff by using has_many, and has_one, and has_and_belongs_to_many relationships in rails.

e.g. if it was facebook, you might have something like this

Class User < ActiveRecord::Base
  has_many :news_items
  has_many :friends
  has_many :messages
end

In your code you could then refer to

@user.news_items
@user.friends
@user.messages

And the relationships would ensure you were only showing information belonging to that user.

(Caveat: in reality the relationships will be more complicated, and you will probably need more complicated logic, but this should get you started)

0

精彩评论

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

关注公众号