I’ve used polymorphic routes which seem to not be QUITE what most
people mean when they use this term. Most discussions are intended to
handle things like:
where the comments controller handles different parent types.
I have often used something more like this:
Each of these are “scoped” such that if a params[:user_id] is present,
it will scope the domains list, via something like:
@domains = @user.domains
@domains = Domains.find :all
@user = User.find params[:user_id]
This technique works well for me, even if not QUITE so DRY as I would
like. However, when the paths get more complicated:
my technique quickly becomes at best complicated, and at worse
impossible to implement and debug easily. This is mainly because some
operations are ALWAYS scoped (modifying a domain, for instance) while
others are not. I suppose I could just check permissions on each
operation and only scope the index method, as that is the only one I
really want to narrow down data for. Once a user lists their domains,
I don’t care if it is used via the /domains/ prefix directly.
However, this means that permission checking will have to occur, where
by scoping it I manage to avoid having to do a lot of this, as all I
need to do is check if curent_user.id == params[:user_id] or if
current_user is an admin.
The additional scoping for direct operations on a specific item seem
to be most of the problem, as it is mostly unnecessary.
Do others have solutions to this sort of problem that are cleaner than
what I have done, or might end up doing?