On 19 Mar., 16:41, elliottg <[email protected]> wrote:
> Thanks for the input David.
>
> I'll explain myself a bit more here, maybe you could help me further?
>
> I am building an interface so an admin can create new users and assign
> them to have either a "user" or "admin" role using
> restful_authentication
> and role_requiremnt.
>
> I have a roles table that I have manually placed two records under the
> Name
> column for both "user" and "admin". These are the only two user roles
> expected.
> It seems that if each time I add a new user and I add a new record
> under the Name column
> of the roles table as well that I am going to have a lot of redundant
> data in roles. IE there could be twenty entries under Name roles that
> say "user" and
> then X amount more that say "admin". It would seem that I only need
> one record
> for each in roles to adhere to some semblance of DB normalcy
> ideals.?.?.
>
> Should only the user table and the join table be updated to somehow
> map to the correct existing roles Name record? IE "user" or "admin".
> And if so, whats the code to do that?
If you would like to associate multiple users with the same two roles
in your database, you would have to do it like this:
@user.roles << Role.find_by_name(params[:role_name])
Keep in mind, that this is going to allow the user to have multiple
roles. The #<< method is going to add another role to the collection
of roles, the user already has. The params[:role_name] is simply the
name of the role, you'ld like the user to have, for example "admin".
--
Cheers,
David Knorr
http://twitter.com/rubyguy
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---