I need to flip this around because I think the way PushType currently does things is conventional Rails, and the alternative would be far less conventional. It might be worth trying to explain how this currently works and I think you’ll see where I’m coming from.
For rendering nodes, PushType inserts one single route into your application, which looks like this:
get '*permalink' => 'front_end#show', as: 'node'
This rule should be at the end of your routes file and acts as a catchall. Throw any url at the route and it will pass the permalink to
PushType::FrontEndController#show, which will attempt to find a node with that permalink and render that node.
At this point I would insist that this is not going against Rails convention in any way. You have a resource (a node) which you are identifying with a permalink and you are calling an action to show/render that resource. Maybe it’s confusing because you can’t see the front end controller in your app - it’s hidden in the PushType engine and maybe it feels like there’s some “magic” going on. But there’s not. It’s actually a pretty simple and standard pattern.
Going back to our routes file above, we need to understand that at the routing level Rails knows nothing about the resource or the node you want to access - it just has a permalink. So it’s impossible to conditionally call a
ArticlesController or a
EventsController using standard Rails routing.
To do this, we’d need to build some kind of middleware that loads the node, works out what type of node it is and then calls the relevant controller. At this point we’re already way off the beaten path when it comes to Rails convention. Our controllers wouldn’t be ActionControllers, they would be some kind of PushTypeController that is made to feel and behave a bit like ActionControllers. We’re basically recreating Rails functionality… which goes back to the point in my first reply.
We could do all this… I haven’t ruled this out. Just haven’t been convinced that it’s worth it.
A couple of other points to reply to:
Use a Rails controller. PushType comes with the worlds greatest web application framework for free . Seriously PushType, will never be better than Rails for developing all the bespoke and unique functionality that every website needs. PushType’s responsiblity is purely for managing content and rendering content. Use Rails for everything else.
I think this is key. I have neglected the docs a bit, and there is nothing in the docs on what we’ve talked about in this topic. I’ll try and prioritise this.