Hi all,
I’m having and issue with a many to many relationship. This is my scenario:
I have a user model, a role model and a role_user model.
Looks something like this:
class User < ActiveRecord::Base
acts_as_audited :protect => false
attr_accessor :password
has_many :role_users
has_many :roles, :through => :role_users
…
end
class Role < ActiveRecord::Base
acts_as_audited
has_many :role_users
has_many :users, :through => :role_users
…
end
class RoleUser < ActiveRecord::Base
acts_as_audited
belongs_to :role
belongs_to :user
…
end
In the user edit form I show one checkbox for each role in order to grant or remove roles to a user. I would like this changes to be auditable.
Right now when I check a checkbox and save a new record appears in the audits table, since a record had been inserted in role_users, but nothing happend when I uncheck a role and save (a record is being deleted from role_users).
It will be great if this could be part of a User change instead of a RoleUser, since it will be a new version of the user, but this is not really a must. More like a nice to have.
Thanks to all in advance and sorry to bother with this newbie question.