Tony Tony
2009-Mar-11 04:19 UTC
Making a user created in a complex (nested) form an admin.
Hi all, I''m using a nested form (http://railscasts.com/episodes/73-complex-forms-part-1) to set up a school + faculty user in a single form. Everything works great following the above screencast. However, I''ve come to a temporary halt when trying to make the first user (the same user that''s created in the nested form along with the school) an administrator. Making the first user of the school an admin is a requirement. My idea of how this *should* work is this: def create @school = School.new(params[:school]) @school.faculties.admin = true ... end Where admin is a field (boolean) in the table and the relationship with school (has_many :faculties) and faculty model (belongs_to :school) is working correctly. This obviously isn''t working though. Probably because the user isn''t created yet when trying to look for @school.faculties. Any suggestions on how to make this work? If you need any other info please let me know and I''ll post as soon as I can! Thanks!! Thanks, -Tony -- 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 -~----------~----~----~----~------~----~------~--~---
Tony Tony
2009-Mar-11 16:11 UTC
Re: Making a user created in a complex (nested) form an admi
Tony Tony wrote:> > My idea of how this *should* work is this: > > def create > @school = School.new(params[:school]) > @school.faculties.admin = true > ... > end >Okay, I got it to work. However I''d love to hear from you guys if this is the "proper" way to go about doing this or if there is a better. def create @school = School.new(params[:school]) @school.faculties.first.admin = true .. end Do note that :admin is NOT attr_accessible. So I don''t think there should be any danger of doing things this way. Again, I''d love to hear your thoughts. -Tony -- 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 -~----------~----~----~----~------~----~------~--~---