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/ClassMethods.html#M001792
--
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
-~----------~----~----~----~------~----~------~--~---