开发者

Form is creating already loaded attributes in addition to new attributes, how do I ignore the first?

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开发者_StackOverflow社区 complicated that these are nested attributes.

Thanks in advance.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜