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?

Thanks a ton for the help here!

On Mar 19, 3:07 am, "[email protected]" <[email protected]> wrote:
> On 18 Mar., 15:04,elliottg<[email protected]> wrote:
>
> > Thanks for the input. That does prevent the error but it does not
> > actually update the roles_users join table that is a part of the habtm
> > association between User and Role.
>
> > I just tried this code within Create and it seems to work:...
> > �...@user = User.new(params[:user])
> > �[email protected](params[:role])
>
> > However, I have a question still. I was assuming that the Roles table
> > would not actually have a new record added when saving an habtm assoc.
> > model. I assumed only the join table and the Users table would be
> > updated. Otherwise it seems as though I would have a lot of redundant
> > data in my Roles table. Am I misunderstanding something here?
>
> I'm not sure how you'ld expect the roles table *not* to be updated. I
> mean, you are telling Rails to build a role:
>
> @user.roles.build(params[:role])
>
> If only the users table and the roles_users table were updated the
> role would not exist. Remember, the join table only contains two
> columns: role_id and user_id. In order to register an HABTM in the
> join table there must be *one* role and *one* user. If it still
> doesn't make sense to you, I recommend that read the documentation for
> HABTM 
> associations:http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMet...
>
> --
> Cheers,
> David Knorrhttp://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
-~----------~----~----~----~------~----~------~--~---

Reply via email to