I''ve got 2 models: School and Student I''m using restful authentication for school so when someone signs up they are routed to schools/new The schools table has info for an admin, but I also need authentication for students. Here is what I was thinking would be the best way to do this: #1 Combine admin and students into User model and have an admin? boolean column. So schools would be info about the school, with no admin info. #2 When logging in, if the user is a student they would check the student checkbox so the query can be against students, rather than schools. I believe this is basically like having 2 authentication systems which seems kind of complicated. Which way would you guys do this? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
jko170 wrote:> I''ve got 2 models: School and Student > > I''m using restful authentication for school so when someone signs up > they are routed to schools/new > The schools table has info for an admin, but I also need > authentication for students. Here is what I was thinking would be the > best way to do this: > > #1 Combine admin and students into User model and have an admin? > boolean column. So schools would be info about the school, with no > admin info. > > #2 When logging in, if the user is a student they would check the > student checkbox so the query can be against students, rather than > schools. I believe this is basically like having 2 authentication > systems which seems kind of complicated. > > Which way would you guys do this?The best way i would suggest you is to identify all the entities for your requirement. Looks like you may need staff model, again teaching and non-teaching staffs. For now with the above two models, instead of using a boolean column, by default have an entry in your Student tables with id = 0, that represents the admin. Any data retrieval will be > 0 "where clause". -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Here''s an approach I''ve used before... you have a user model and a role model and then you link the two. class Role < ActiveRecord::Base has_and_belongs_to_many :users end class User < ActiveRecord::Base has_and_belongs_to_many :roles def has_role(role) self.roles.detect(|r| r.name == role} end def is_student? self.has_role?("student") end def is_admin? self.has_role?("admin") end end Role.create :name=>"admin" Role.create :name=>"student" user = User.create :last_name=>"Simpson", :first_name=>"Homer", :password=>"1234", :password_confirmation=>"1234", :email=>" homer-SObyMCWwuh1Wk0Htik3J/w@public.gmane.org", :login=>"homer" user.roles << Role.find_by_name "admin" user.roles << Role.find_by_name "student" Makes it really easy then, cos in your views, if you use restful_auth or acts_as_authenticated, your current_user will have a .is_admin? on it. <% if current_user.is_admin? %> ... show stuff for admins <% end %> Hope that helps. -Brian On 5/14/07, Syed Arif <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > jko170 wrote: > > I''ve got 2 models: School and Student > > > > I''m using restful authentication for school so when someone signs up > > they are routed to schools/new > > The schools table has info for an admin, but I also need > > authentication for students. Here is what I was thinking would be the > > best way to do this: > > > > #1 Combine admin and students into User model and have an admin? > > boolean column. So schools would be info about the school, with no > > admin info. > > > > #2 When logging in, if the user is a student they would check the > > student checkbox so the query can be against students, rather than > > schools. I believe this is basically like having 2 authentication > > systems which seems kind of complicated. > > > > Which way would you guys do this? > > The best way i would suggest you is to identify all the entities for > your requirement. Looks like you may need staff model, again teaching > and non-teaching staffs. > > For now with the above two models, instead of using a boolean column, by > default have an entry in your Student tables with id = 0, that > represents the admin. Any data retrieval will be > 0 "where clause". > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I''ll give this a try, thanks a lot! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---