Building a static mirror of a Rails site?

Hello Rails List!
Thanks to those who commented on my prior thread about credit card handling; some smart, smart people on this list.

Here’s another one for you: I have a client for whom I’m building a site. They insist on using their existing webhost, which runs PHP 4.3. OK, cool.

Luckily, for now, the site is going to be largely static. I could use, say, Dreamweaver and build everything using Dreamweaver templates, but I would much rather hang the site off Rails for the following reasons:

  1. Dreamweaver is US$400. Rails, SVN, and a text editor are free.

  2. I’m likely to be more productive in Rails, since I haven’t touched Dreamweaver or its templating system for a few years.

  3. Building it in Rails today offers a degree of futureproofing, for when the client calls me 6 months from now and says “we’d like to add a blog, a booking system, a forms repository, and oh… can we have the ability to edit everything over the web?”

  4. OMGWTFBBQ. Rails is, like, my BFF xoxoxox <3

Then I got to thinking… I wonder if there’s a way to build a Rails site (which doesn’t use POST requests), and then dump the whole thing out – links, media, and all – to a set of static pages and files for launch on a plain webserver? I did a little searching on the web and on the Rails list; there were some folks a while back talking about using httrack, or wget to create a static mirror of a running Rails site. I gave it a shot with wget, and it showed some promise except for a few bugaboos:

  1. http://mydomain.com/controller/action” will get saved into a file named “action” in a “controller” directory. The lack of .htm extension on the file causes at least one webserver I tried this on to freak out and send the static file to the browser using a non-HTML content type. This, in turn, causes the HTML source to be displayed in the browser in plain text.

  2. http://mydomain.com/controller/action/” will fail (note the trailing slash) since no “action” directory exists. #1 and #2 could be solved if wget would simply save the output of “http://mydomain.com/controller/action” to a file named “index.htm” in a “controller/action” directory.

  3. wget will save image/css/js files along with Rails’ new timestamping/cachebusting tack-on, resulting in filenames such as “image.gif?44702193412”. This will, of course, break the static site, since the webserver strips everything after the “?” when trying to access whatever file.

So – what do you think? Comments? Suggestions? Links to prior art that I might have missed?

Cheers,

Steven Luscher (BDes Hons., Provisional RGD)

{

c = Steven Luscher Design;

w = [http://www.stevenluscherdesign.com](http://www.stevenluscherdesign.com)/

}

Steven Luscher wrote:

*Then I got to thinking... I wonder if there's a way to build a Rails site (which doesn't use POST requests), and then dump the whole thing out – links, media, and all – to a set of static pages and files for launch on a plain webserver?* I did a little searching on the web and on

Could you use page caching on all controllers/action. Visit all pages (perhaps programatically with a rake task) and then copy all the file in public/ up to the webserver (perhaps with a rake task or Capistrano setup).

Eric

using httrack, or wget to
create a static mirror of a running Rails site. I gave it a shot with wget,
and it showed some promise except for a few bugaboos:

1) "http://mydomain.com/controller/action" will get saved
into a file named "action" in a "controller" directory. The lack of .htm
extension on the file

wget --html-extension

causes at least one webserver I tried this on to freak
out and send the static file to the browser using a non-HTML content type.
This, in turn, causes the HTML source to be displayed in the browser in
plain text.

2) "http://mydomain.com/controller/action/" will fail (note
the trailing slash) since no "action" directory exists. #1 and #2 could be
solved if wget would simply save the output of
"http://mydomain.com/controller/action" to a file named
"index.htm" in a "controller/action" directory.

wget --no-directories

man wget

Could you use page caching on all controllers/action.
I was going to mention this, but thought I’d wait until someone brought it up. Could that actually work?

Steven Luscher wrote:

Hi all,

I have a question about the following ticket. The patch provided on this ticket fixes the problem (for me). Despite this fact, I don't see this code in the trunk. Can someone tell me why this is?

Another thing is that I tried to override this function in the lib directory, with the patch applied, but somehow, it still uses the old code. I wanted to fix my problem in a clean way by overriding the actioncontroller module. But I can't get it working. And hacking a gem myself isn't a long term solution.

Thanks in advance,
Jeroen van Doorn

Steven Luscher wrote:

So ? what do you think? Comments? Suggestions? Links to prior art
that I might have missed?

I have posted a similar question but got no replies... I am very interested
though! I guess a good rake task can do the job...

Bart