# Making a user created in a complex (nested) form an admin

**URL:** <https://www.ruby-forum.com/t/making-a-user-created-in-a-complex-nested-form-an-admin/162540>\
**Category:** Rails\
**Created:** [March 11, 2009, 5:19am UTC](https://www.ruby-forum.com/t/making-a-user-created-in-a-complex-nested-form-an-admin/162540 "2009-03-11T05:19:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bagadoughnuts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@bagadoughnuts](https://www.ruby-forum.com/u/bagadoughnuts)\
**Post date:** [March 11, 2009, 5:19am UTC](https://www.ruby-forum.com/t/making-a-user-created-in-a-complex-nested-form-an-admin/162540/1 "2009-03-11T05:19:52Z")

</div>

Hi all,

I’m using a nested form  
([#73 Complex Forms Part 1 - RailsCasts](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

---

<div class="post-metadata">

**Author:** ![bagadoughnuts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@bagadoughnuts](https://www.ruby-forum.com/u/bagadoughnuts)\
**Post date:** [March 11, 2009, 5:11pm UTC](https://www.ruby-forum.com/t/making-a-user-created-in-a-complex-nested-form-an-admin/162540/2 "2009-03-11T17:11:57Z")

</div>

Tony T. 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
