<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>State Of Flux &#187; static</title>
	<atom:link href="http://stateofflux.com/tag/static/feed/" rel="self" type="application/rss+xml" />
	<link>http://stateofflux.com</link>
	<description>always changing</description>
	<lastBuildDate>Fri, 29 Jan 2010 03:29:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Generate static pages in Rails</title>
		<link>http://stateofflux.com/2008/07/14/generate-static-pages-in-rails/</link>
		<comments>http://stateofflux.com/2008/07/14/generate-static-pages-in-rails/#comments</comments>
		<pubDate>Mon, 14 Jul 2008 11:05:00 +0000</pubDate>
		<dc:creator>mark</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[404]]></category>
		<category><![CDATA[500]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[errorpages]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rake]]></category>
		<category><![CDATA[static]]></category>

		<guid isPermaLink="false">http://markmansour.wordpress.com//2008/07/14/generate-static-pages-in-rails</guid>
		<description><![CDATA[I wanted a nice looking 404, 500 and maintenance pages for my Rails app and I couldn&#8217;t serve them from Rails. My requirements were: I didn&#8217;t want to hand code the pages &#8211; I&#8217;m using a web framework for a reason! I wanted to use the application&#8217;s layout I needed that pages to be static [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted a nice looking 404, 500 and maintenance pages for my Rails app and I couldn&#8217;t serve them from Rails.</p>
<p>My requirements were:</p>
<ul>
<li>I didn&#8217;t want to hand code the pages &#8211; I&#8217;m using a web framework for a reason!</li>
<li>I wanted to use the application&#8217;s layout</li>
<li>I needed that pages to be static so I could serve them when the Rails app was either down or when it had &#8216;issues&#8217;</li>
</ul>
<p>My solution was to:</p>
<ol>
<li>create a controller for the purpose of rendering the static pages</li>
<li>tailor your views so you have nice 404, 500 and maintenance pages</li>
<li>modify the layout so that signin and register were not longer present</li>
<li>create a rake task to render the pages and write them out to a file</li>
</ol>
<p>Items 1 &#38; 2 are just standard Rails stuff &#8211; so go nutz young coders.</p>
<p>Item 3 was pretty straight forward, in the layout I put:</p>
<pre lang="ruby">
  <% unless controller.controller_name == "errors" %>
     put your sign-in code here
  <% end %>
</pre>
<p>Item 4 was a bit trickier, but this rake task should get you up and running.</p>
<pre lang="ruby">
  namespace :generate do
    task :pages => :environment do
      require 'action_controller/integration'
      app = ActionController::Integration::Session.new
      app.host! "stateofflux.com"
      [['/errors/error_404', 'public/40 4.html'],
       ['/errors/error_500', 'public/500.html']].each do |url, file|
        begin
          app.get url
          File.open(file, "w") { |f| f.write app.response.body }
        rescue Exception => e
          puts "Could not write file #{e}"
        end
      end
    end
  end
</pre>
<p>We run the rake task in the development environment then check it in, but you could run it in production if there was production data that you needed to create the page.</p>
]]></content:encoded>
			<wfw:commentRss>http://stateofflux.com/2008/07/14/generate-static-pages-in-rails/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
