I'm writing a CMS/portal system, and I'm having trouble coming up with
a way of routing requests that feels right without using render
:component (which I've read should never be used). The system works
Each user has a set of "pages" which are shown as navigation tabs on
the page. The user may rename, reorder, add, or delete pages for a
custom view of the site. Pages can be of a number of types (calendars,
blogs, links pages, to do lists, etc).
If the user, joe, makes a page called "My Calendar" it's URL would be
Once a request comes in for that URL, I need to hit the database in
order to figure out how to route it. I have to figure out what type of
page "my-calendar" maps to and ensure that joe has permission to view
that page. As far as I can tell, it's not possible to handle this in
routes.rb, so I put it in a controller, PageController.
Once the app determines what kind of controller is required, it needs
to pass on the request to the appropriate controller (a
CalendarController, BlogController, ToDoController, etc). It seems
like the most straightforward way of doing this is to have the last
line of PageController's routing function be "render :component => ..."
I have managed to use what I consider to be a gigantic hack to get
around this. PageController figures out which controller needs to
handle the final request, instantiates it, calls the appropriate
function on it, reflects all of that function's local variables into
its own, and then calls the appropriate render :action. The code for
this is pretty ugly, and reflecting private variables like that makes
the software engineer part of me want to cry.
So, what's the proper way of handling this without using render
:component? What am I doing wrong?