I know the subject has been discussed a lot already, and there's
plenty of articles about it on the web. But I still haven't figured
out a solution to my problem, so here goes a cry for help.
I have the following custom route in my application:
map.connect '/:username', :controller => 'public', :action =>
Basically, I want my users to be able to access their personal page
through the "shortcut" www.mywebsite.com/username, so once that URL is
entered or clicked, I redirect them to the appropriate action, which
is show_profile. There I have a simple code, kinda like this
@user = User.find_by_username(params[:username])
to retrieve their data from the DB.
This solution works great, but since their personal pages will be
rarely updated, I want to use page caching to store it in a HTML file
and avoid all Rails processing/DB queries, expiring the cache just
when I actually need to.
And now enters my problem. Rails is saving the cached pages as
show_profile.html. That clearly doesn't work, since each user must
have a different cached HTML with their specific data. I want the
cached HTML files to be named after the username (username.html) not
after the action (show_profile.html).
I've managed to make this work by adding the controller and action to
the route, like this
map.connect '/public/show_profile/:username', :controller =>
'public', :action => 'show_profile'
and then my cached files would be stored in a 'public/show_profile/
But I really need the URLs to be simple as www.mywebsite.com/username,
so that doesn't work. And as only fragment caching accepts a
'action_suffix' parameter, I really can't figure how to work this out
with page caching.