From what you describe (which is not much, i have to guess your
relations), would think this is
what you think of:
class ForumPerms ActiveRecord::Base
belongs_to :forum
belongs_to :usergroup
end
class Forum ActiveRecord::Base
has_many :forum_perms
end
class Usergroup ActiveRecord::Base
has_many :forum_perms
def has_access_on(forum,accparams)
forumperm = ForumPerm.new(accparams)
forumperm.forum = forum
forumperm.user = self
forumperm.save
end
end
see? no HABTM, just 2 has_many <-> belongs_to
and i added a method to the user class to easily add a new permission
for a forum to a group:
the you can simply do:
usergroup = Usergroup(1) # select some group for this example
forum = Forum(1) # select some forum for this example
@usergroup.has_access_on(forum, {:read => true, :write => false, :post
=> true } )
what is done in the method can be done "by hand" in the controller too,
its just nicer this way ... and maybe there are may be nicer ways,
As always: im more a new rails user, and make many mistakes so dont be
disappointed if i made some errors...
Do you have the following relationships between your tables?
a) Does forum have many usergroups?
b) Does usergroup have many forums?
The forum_perms looks like the join table with additional attributes associated to break the many-to-many relationship between the other two tables. If so then you need to use has_many :through to deal with this scenario.