<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Quick and easy static pages in Rails</title>
	<atom:link href="http://www.mendable.com/quick-and-easy-static-pages-in-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mendable.com/quick-and-easy-static-pages-in-rails/</link>
	<description>Mendable.com - Essential Reading for Ruby on Rails Developers</description>
	<lastBuildDate>Wed, 28 Jul 2010 07:26:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Fadhli Rahim</title>
		<link>http://www.mendable.com/quick-and-easy-static-pages-in-rails/comment-page-1/#comment-214</link>
		<dc:creator>Fadhli Rahim</dc:creator>
		<pubDate>Tue, 23 Feb 2010 08:27:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.mendable.com/?p=235#comment-214</guid>
		<description>Hi, Josh Susser from has_many :through blog had long ago blogged something very similiar. Here&#039;s the link

http://blog.hasmanythrough.com/2008/4/2/simple-pages</description>
		<content:encoded><![CDATA[<p>Hi, Josh Susser from has_many :through blog had long ago blogged something very similiar. Here&#8217;s the link</p>
<p><a href="http://blog.hasmanythrough.com/2008/4/2/simple-pages" rel="nofollow">http://blog.hasmanythrough.com/2008/4/2/simple-pages</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.mendable.com/quick-and-easy-static-pages-in-rails/comment-page-1/#comment-212</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Sat, 20 Feb 2010 13:41:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.mendable.com/?p=235#comment-212</guid>
		<description>@ daeltar &amp; @Ben Hughes - the line is not unsafe as the controller action would never be invoked unless the id is in the pre-approved routing. (I never used the default /:controller/:action/:id routes). I suppose if someone does use those default routes it might be worth looking into.

@Aleksey Gureiev - I liked your approach it was a bit DRYer but still clear and easy to comprehend quickly.

@ Luke - Thanks for the input

@ Mark Richman  - Yep, i&#039;m using shoulda for testing.</description>
		<content:encoded><![CDATA[<p>@ daeltar &#038; @Ben Hughes &#8211; the line is not unsafe as the controller action would never be invoked unless the id is in the pre-approved routing. (I never used the default /:controller/:action/:id routes). I suppose if someone does use those default routes it might be worth looking into.</p>
<p>@Aleksey Gureiev &#8211; I liked your approach it was a bit DRYer but still clear and easy to comprehend quickly.</p>
<p>@ Luke &#8211; Thanks for the input</p>
<p>@ Mark Richman  &#8211; Yep, i&#8217;m using shoulda for testing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aleksey Gureiev</title>
		<link>http://www.mendable.com/quick-and-easy-static-pages-in-rails/comment-page-1/#comment-209</link>
		<dc:creator>Aleksey Gureiev</dc:creator>
		<pubDate>Sat, 13 Feb 2010 22:33:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.mendable.com/?p=235#comment-209</guid>
		<description>@ö: Having inexplicit routes like that isn&#039;t a very good thing. First of all, you will be running code checking for static pages whenever any missing resource is requested (images etc). Secondly, unless you have a CMS of a sort, stating the names of static pages is way better for readability. You don&#039;t have too many of them in your average app.</description>
		<content:encoded><![CDATA[<p>@ö: Having inexplicit routes like that isn&#8217;t a very good thing. First of all, you will be running code checking for static pages whenever any missing resource is requested (images etc). Secondly, unless you have a CMS of a sort, stating the names of static pages is way better for readability. You don&#8217;t have too many of them in your average app.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aleksey Gureiev</title>
		<link>http://www.mendable.com/quick-and-easy-static-pages-in-rails/comment-page-1/#comment-208</link>
		<dc:creator>Aleksey Gureiev</dc:creator>
		<pubDate>Sat, 13 Feb 2010 00:01:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.mendable.com/?p=235#comment-208</guid>
		<description>Evidently, it didn&#039;t like my using of angle brackets in step 3. Here&#039;s what I meant: &quot;Create _page_.html.erb files ...&quot;</description>
		<content:encoded><![CDATA[<p>Evidently, it didn&#8217;t like my using of angle brackets in step 3. Here&#8217;s what I meant: &#8220;Create _page_.html.erb files &#8230;&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aleksey Gureiev</title>
		<link>http://www.mendable.com/quick-and-easy-static-pages-in-rails/comment-page-1/#comment-207</link>
		<dc:creator>Aleksey Gureiev</dc:creator>
		<pubDate>Fri, 12 Feb 2010 23:59:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.mendable.com/?p=235#comment-207</guid>
		<description>Hi,

Can I suggest a slightly shorter approach? Here&#039;s what I have in mind:

1) Create an empty StaticPages controller and write the tests. As you will see, I&#039;m accessing pages through the same URLs, but not calling a :show action, but calling actions with the same name as the page (:faq, :about etc). This is a great way to customize each action if necessary and leave everything else untouched. 

http://gist.github.com/303124

2) Create routes:

http://gist.github.com/303127

3) Create ,html.erb files for each of the pages in your app/views/static_pages directory.

As you can see, I&#039;m not adding any actions to the StaticPagesController. It is absolutely empty. When Rails see the action that is not in the controller, it first checks if the template is there and only if it&#039;s not, throws an exception.

Now to customize any of the pages (for example, to fetch some page-related data, like contacts from the database etc), you can add an action method to the controller, assign instance variables and start using them in that template only.

Hope you like it.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Can I suggest a slightly shorter approach? Here&#8217;s what I have in mind:</p>
<p>1) Create an empty StaticPages controller and write the tests. As you will see, I&#8217;m accessing pages through the same URLs, but not calling a :show action, but calling actions with the same name as the page (:faq, :about etc). This is a great way to customize each action if necessary and leave everything else untouched. </p>
<p><a href="http://gist.github.com/303124" rel="nofollow">http://gist.github.com/303124</a></p>
<p>2) Create routes:</p>
<p><a href="http://gist.github.com/303127" rel="nofollow">http://gist.github.com/303127</a></p>
<p>3) Create ,html.erb files for each of the pages in your app/views/static_pages directory.</p>
<p>As you can see, I&#8217;m not adding any actions to the StaticPagesController. It is absolutely empty. When Rails see the action that is not in the controller, it first checks if the template is there and only if it&#8217;s not, throws an exception.</p>
<p>Now to customize any of the pages (for example, to fetch some page-related data, like contacts from the database etc), you can add an action method to the controller, assign instance variables and start using them in that template only.</p>
<p>Hope you like it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ö</title>
		<link>http://www.mendable.com/quick-and-easy-static-pages-in-rails/comment-page-1/#comment-204</link>
		<dc:creator>ö</dc:creator>
		<pubDate>Thu, 11 Feb 2010 19:14:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.mendable.com/?p=235#comment-204</guid>
		<description>I find it DRYer to pass a catch-all *path parameter to the static_pages controller and check in the controller if the corresponding template exists, as described in http://snafu.diarrhea.ch/blog/article/4-serving-static-content-with-rails . This way you don&#039;t need to add a custom route and restart Rails every time you add a page. It also allows for mod_rewrite-like functionality and subdirectories.</description>
		<content:encoded><![CDATA[<p>I find it DRYer to pass a catch-all *path parameter to the static_pages controller and check in the controller if the corresponding template exists, as described in <a href="http://snafu.diarrhea.ch/blog/article/4-serving-static-content-with-rails" rel="nofollow">http://snafu.diarrhea.ch/blog/article/4-serving-static-content-with-rails</a> . This way you don&#8217;t need to add a custom route and restart Rails every time you add a page. It also allows for mod_rewrite-like functionality and subdirectories.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Richman</title>
		<link>http://www.mendable.com/quick-and-easy-static-pages-in-rails/comment-page-1/#comment-203</link>
		<dc:creator>Mark Richman</dc:creator>
		<pubDate>Thu, 11 Feb 2010 18:19:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.mendable.com/?p=235#comment-203</guid>
		<description>Note the functional test requires Shoulda for the should_route method.</description>
		<content:encoded><![CDATA[<p>Note the functional test requires Shoulda for the should_route method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Luke</title>
		<link>http://www.mendable.com/quick-and-easy-static-pages-in-rails/comment-page-1/#comment-202</link>
		<dc:creator>Luke</dc:creator>
		<pubDate>Thu, 11 Feb 2010 16:50:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.mendable.com/?p=235#comment-202</guid>
		<description>I wanted to share my approach to this problem. Thanks for the post!

http://www.lukecowell.com/archives/2010/2/11/static_pages_in_rails/</description>
		<content:encoded><![CDATA[<p>I wanted to share my approach to this problem. Thanks for the post!</p>
<p><a href="http://www.lukecowell.com/archives/2010/2/11/static_pages_in_rails/" rel="nofollow">http://www.lukecowell.com/archives/2010/2/11/static_pages_in_rails/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sander</title>
		<link>http://www.mendable.com/quick-and-easy-static-pages-in-rails/comment-page-1/#comment-200</link>
		<dc:creator>Sander</dc:creator>
		<pubDate>Thu, 11 Feb 2010 08:36:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.mendable.com/?p=235#comment-200</guid>
		<description>Even less code and easier to extend:
# Routes.rb:
  map.connect &#039;:page.html&#039;, :controller =&gt; &#039;main&#039;, :action =&gt; &#039;render_html&#039;

# main_controller.rb
def render_html
  render :template =&gt; &quot;main/#{params[:page]}&quot; if template_exists?(&quot;main/#{params[:page]}&quot;)
end</description>
		<content:encoded><![CDATA[<p>Even less code and easier to extend:<br />
# Routes.rb:<br />
  map.connect &#8216;:page.html&#8217;, :controller =&gt; &#8216;main&#8217;, :action =&gt; &#8216;render_html&#8217;</p>
<p># main_controller.rb<br />
def render_html<br />
  render :template =&gt; &#8220;main/#{params[:page]}&#8221; if template_exists?(&#8220;main/#{params[:page]}&#8221;)<br />
end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arthur Gunn</title>
		<link>http://www.mendable.com/quick-and-easy-static-pages-in-rails/comment-page-1/#comment-199</link>
		<dc:creator>Arthur Gunn</dc:creator>
		<pubDate>Wed, 10 Feb 2010 23:13:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.mendable.com/?p=235#comment-199</guid>
		<description>So the pages_controller was butchered there. The relevant bit is that pages_controller&#039;s show method just has one line:

render :action =&gt; params[:page]

...hope that comes through</description>
		<content:encoded><![CDATA[<p>So the pages_controller was butchered there. The relevant bit is that pages_controller&#8217;s show method just has one line:</p>
<p>render :action =&gt; params[:page]</p>
<p>&#8230;hope that comes through</p>
]]></content:encoded>
	</item>
</channel>
</rss>
