The skinny is that I’m attempting to add “Discussions” as resources
under different resources (“Groups”, “Projects”, for example) and I’ve
simply hit a roadblock (or two).
Discussions are an association between the “discussable” (Group,
Project, etc.) and a “Topic” so:
class Discussion < ActiveRecord::Base
belongs_to :topic
belongs_to :discussable, :polymorphic => true
end
The roadblock comes about in a few places; when wanting to reference a
discussion’s “discussable” for using the resource methods for pathing:
discussion_path(@discussable, @discussion). Here I did a check to see
what discussable ids are present in the params. So that is solved
though not as nice as I’d like.
That managed to get me through the first roadblock but then I realised
that now I’d have to do all sorts of logic elsewhere to determine what
@discussable is and how to treat it (if its a Group or a Project, etc).
I’m hoping that I’m unaware of a way of dealing with this kind of thing
and that hopefully someone here can shed some light on it. However, if
not, I guess I’ve got my work cut out for me. I suppose the solution
would be some sort of formalized way of dealing with polymorphic
resources. I’d have to devote some serious thought to that though.
Any help is appreciated.
Thanks.