Building a static mirror of a Rails site?

Hello Rails L.!
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 L. (BDes Hons., Provisional RGD)
{
c = Steven L. Design;
w = http://www.stevenluscherdesign.com/
}

Steven L. 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

On 9/11/06, Steven L. [email protected] wrote:

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.

  1. 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


Greg D.
http://destiney.com/

Steven L. wrote:

On 11-Sep-06, at 5:18 PM, Eric A. wrote:

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?

As long as you remember to run the app in production mode, it should.
Then simply use wget to traverse the site, triggering all actions, and
upload the cached files in public/ (ie not the wget files) to the host.


Jakob S. - http://mentalized.net

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

On 11-Sep-06, at 5:18 PM, Eric A. wrote:

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?

On 11-Sep-06, at 5:32 PM, Greg D. wrote:

wget --html-extension
wget --no-directories

Thanks for the notes Greg! “wget -k --html-extension --no-
directories” solves a couple of problems, but creates another; if
we’re going to start letting wget rename links and tack on .html
extensions, then when we eventually do launch the site on Rails, any
links made to the site from the outside will break (http://
mydomain.com/controller/action.html will become “http://mydomain.com/
controller/action” again).

Steven L. (BDes Hons., Provisional RGD)
{
c = Steven L. Design;
w = http://www.stevenluscherdesign.com/
}

i was going to post the same question after i completed my first rails
app. it would be so nice to have a rake command that would do this and
create a whole new directory with all the static content!

Steven L. 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