Tuesday, 15 March 2011

Modeling Users in Rails -


I need advice / help in applying the design of my model which I am currently developing. First of all, I have my own fields for my table with these models:

  students * Various areas faculty * Various fields user * Username * password_digest  

I have student and faculty items for the CRUD, which have their own unique fields / properties in their own tables. At the same time, I see these items as the types of users who use the app .

How am I complicating them as models, either using ActiveCard's STI or polymorphism techniques. All I want is to recognize the type of user that is signing the app and display or redirect it to the appropriate page for that type of user. At the same time, the faculty or student is in reference to his related records in the table

assuming that I have these conditions, what is the best way to reach them:

  • Users can either be a student, faculty or administration, later I / Model non-faculty members can also add to the application.

  • Students / Faculties can not or can not choose an affiliate user account (some students and faculty members do not want to use the app)

  • The admin users have access to the administrative (CRUD) side of the app. Students and faculty can only handle their own records.

I may be wrong, but my condition is to go polymorphic and insert the context in the user model:

  class user & Lt; ActiveRecord :: Base is_to: usable, polymorphic: true and class student & lt; ActiveRecord :: Base is_on: user, such as: UserAbbble and Class Faculty & Lt; ActiveRecord :: Base has_one: user, as :: userable end  

PS: I do not know the word "user-friendly" is right, tell me right if the name is a better way. .

There is a simple way, you can easily manage it even with normal areas

  # The user must be a type of field (string) class user & lt; ActiveRecord :: Base & Class Student & lt; User's end class faculty & lt; User end  

No comments:

Post a Comment