views:

48

answers:

1

In my application you:

  1. Have an admin user that signs on and that user has a role (separate model), then I use the declarative_authorization plugin to give access to certain areas.

  2. That admin user can also register new users in the system, when they do this (using Authlogic) they fill out a nested form that includes that new users' role.

So what is happening is the role of the admin user is being loaded by the declarative_authorization and then the nested form using the has_many_nested_attributes is loading that existing role as well as the new role for the new user (users can have many roles).

Is there some way I can tell the new User being created to ignore the role assigned to the current_user and only create the role in the form for the new user?

I have looked through a lot of different things, but it seems to get more complicated that these are nested attributes.

Thanks in advance.

A: 

Why would you create a new role when creating a new user? I would only assign a new user to specific roles instead of creating a bunch of new roles to a new user.

Try this in your view:

collection_select :user,"role_ids[]", Roles.all, :id, :name, {}, {:multiple=>true}

instead of Roles.all, you could also use

Roles.find(:conditions=>"role_name IS NOT 'admin'")

to exclude the "Admin" role.

LWille