Roles Select?

11 views
Skip to first unread message

Shaun

unread,
Jan 7, 2011, 4:49:09 PM1/7/11
to acl9-discuss
I have searched everywhere and tried to find an example of using ACL9
to generate a select form for use in a new user form. Is there any
place that I can find an example of a view and controller that have a
"role select" implementation?

Kevin Monk

unread,
Jan 8, 2011, 11:37:52 AM1/8/11
to acl9-discuss
I'm having the same issue except I'm wishing to use a check_box for
the roles.

At the moment I have something that looks a little like this...

- fields_for @user do |user_form|
- user_form.fields_for :assign_roles do |role_form|
- Role::POSSIBLE_ROLES.each do |role|
%p
= role_form.check_box role, :checked => @user.has_role?(role)
= role_form.label role.humanize

but when I do this then in the params hash I get something like
this....

"assign_roles"=>{"super_administrator"=>"0", "administrator"=>"1"}

Was hoping I could use the standard @user.update_attributes by making
my filelds_for :roles

but that's not helping me too much.

Would be interested to know where you got to with it.

Shaun Gish

unread,
Jan 8, 2011, 12:39:23 PM1/8/11
to acl9-d...@googlegroups.com
Here's what I ended up doing:

http://rails.pastebin.com/N8V3QWjy

Basically I ended up defining a custom getter/setter... not sure if this is the right way or best way to do it but it worked for me

Kevin Monk

unread,
Jan 8, 2011, 2:57:09 PM1/8/11
to acl9-discuss
THanks Shaun.

The more I look at some of the other posts on here, the more I
realised that assigning multiple global roles to a single user
probably wasn't going to do me much good.

I ended up just changing to a single global role per user and then
creating make_admin and remove_admin routes and associated controller
actions and then only only allow access to those methods for admins.

It seems to be a recurring theme that if I've got stuck on something
it's normally because I have the structure a little skewy. Not always
easy to see where you're making a fundamental miscomprehension though
I guess.

Shaun Gish

unread,
Jan 8, 2011, 3:14:45 PM1/8/11
to acl9-d...@googlegroups.com
Yea... I'm kind of the same way...

Although it would be really nice if ACL9 had some sort of helper functions for things like this... or even just a couple of examples to learn from.
Reply all
Reply to author
Forward
0 new messages