<?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>Tea-Driven Development &#187; controllers</title>
	<atom:link href="http://blog.mattwynne.net/tag/controllers/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mattwynne.net</link>
	<description>Matt Wynne taking it one tea at a time</description>
	<lastBuildDate>Tue, 10 Jan 2012 20:07:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Nested Controllers and Broken link_to</title>
		<link>http://blog.mattwynne.net/2007/06/16/nested-controllers-and-broken-link_to/</link>
		<comments>http://blog.mattwynne.net/2007/06/16/nested-controllers-and-broken-link_to/#comments</comments>
		<pubDate>Sat, 16 Jun 2007 19:40:17 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[books]]></category>
		<category><![CDATA[controllers]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://blog.mattwynne.net/2007/06/16/nested-controllers-and-broken-link_to/</guid>
		<description><![CDATA[So my first little rails app is taking it&#8217;s baby steps in the wild today, and some users should hit the site over the weekend&#8230; Exciting stuff. I&#8217;ve written an admin area for the site, and with only a tentative grasp on the whys and wherefores, I&#8217;ve copied something I saw in the mephisto source [...]]]></description>
			<content:encoded><![CDATA[<p>So my first little rails app is taking it&#8217;s baby steps in the wild today, and some users should hit the site over the weekend&#8230; Exciting stuff.</p>

<p>I&#8217;ve written an admin area for the site, and with only a tentative grasp on the whys and wherefores, I&#8217;ve copied something I saw in the mephisto source code and used &#8216;nested controllers&#8217; to keep the admin code tucked away from the rest:
<pre>
<code>
$script/generate controller admin/users
$script/generate controller admin/stuff
</code></pre>
For want of a better way, I put a base class for the admin controllers into the application.rb file (can&#8217;t remember where I picked this tip up) and put a one-line before_filter on that class to check whether the user has the appropriate rights. Sweet.</p>

<p>The little gotcha with this was that a lot of my existing link<em>to and redirect</em>to calls didn&#8217;t work from within the admin area, because I guess the :controller value in the options is relative. Adding a forward-slash to the controller name fixes it up:
<pre>
<code>
&lt;%= link_to 'home', :controller =&gt; '/home' %&gt;
</code></pre>
Looks like <a href="http://blogs.herod.net/steven/nesting-controllers-with-rubyonrails/">not the only one</a> to have hit this little bump.</p>

<p>I think I need a new rails book: I&#8217;m starting to leave my trusty <a href="http://www.pragmaticprogrammer.com/titles/rails/">pragprog</a> book behind. Any recommendations out there people?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mattwynne.net/2007/06/16/nested-controllers-and-broken-link_to/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

