I’m a relative Rails Noob developing a CMS using rails. I have
designed it so that all the public urls are created using an admin
tool and stored in a database. I then want to use routes to direct the
visitor to the appropriate action of a single controller.
The way I see it there are three ways of doing this:
- Use components - I’d rather not as they are slow and dont really
represent what I am trying to do
- Somehow extract the id of the page using the path from the database
within routes.rb, use that to get the appropriate action - I cant
figure out how to do this in routes.rb
- Redirect to a single action which can then point to another action
- Sort of what I’m already doing but as far as I know there is no way
for a rails action to ‘render’ another action
Here is the route I am using:
map.connect '*path', :controller => "public", :action => "page"
And here is the page action in PublicController:
def page @page = Page.find_from_path(params[:path])
render :action => @page.template, :layout =>
As you can see I would like to define the template and the layout
(actually should be the action) in the database but I just cant work
out a way to do it.
I have spent a long time trawling the web for a possible solution but
have found nothing so far. If anyone could help come up with a
solution in any way I would be immensely grateful.