<?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"
	>
<channel>
	<title>Comments on: before_filter and with_scope</title>
	<atom:link href="http://marcus.ahnve.net/2006/05/09/before_filter-and-with_scope/feed/" rel="self" type="application/rss+xml" />
	<link>http://marcus.ahnve.net/2006/05/09/before_filter-and-with_scope/</link>
	<description>A northern, icebears-on-the-streets, view on programming, music etc. from Marcus Ahnve</description>
	<pubDate>Fri, 21 Nov 2008 04:16:01 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: Jon Tirsen</title>
		<link>http://marcus.ahnve.net/2006/05/09/before_filter-and-with_scope/#comment-644</link>
		<dc:creator>Jon Tirsen</dc:creator>
		<pubDate>Tue, 09 May 2006 01:06:16 +0000</pubDate>
		<guid isPermaLink="false">http://marcus.ahnve.net/?p=126#comment-644</guid>
		<description>&lt;p&gt;I've been digging into this too. No you can't use either a before&lt;em&gt;filter or an around&lt;/em&gt;filter to do this using the public API. The problem is that around&lt;em&gt;filter's in Rails aren't actually around&lt;/em&gt;filter's they're more like a before/around-filter combo. A real around_filter could do:&lt;/p&gt;

&lt;p&gt;class ScopingFilter
  def around
    DomainObject.with_scope(...) do
      yield # passes control to controller
    end
  end
end&lt;/p&gt;

&lt;p&gt;But unfortunately Rails isn't capable of that. So instead the plugin has to use module_eval to dive into the private parts of the domain object and chuck in a scope in the "before" part of the "around" filter then dive in again and yank it out in the "after" part.&lt;/p&gt;

&lt;p&gt;Ugly? Oh yeaaaah... Pretty brutal rummaging around with another objects private parts like that.&lt;/p&gt;

&lt;p&gt;Maybe it's time somebody teaches Rails Core what "around" really means...&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I&#8217;ve been digging into this too. No you can&#8217;t use either a before<em>filter or an around</em>filter to do this using the public API. The problem is that around<em>filter&#8217;s in Rails aren&#8217;t actually around</em>filter&#8217;s they&#8217;re more like a before/around-filter combo. A real around_filter could do:</p>

<p>class ScopingFilter
  def around
    DomainObject.with_scope(&#8230;) do
      yield # passes control to controller
    end
  end
end</p>

<p>But unfortunately Rails isn&#8217;t capable of that. So instead the plugin has to use module_eval to dive into the private parts of the domain object and chuck in a scope in the &#8220;before&#8221; part of the &#8220;around&#8221; filter then dive in again and yank it out in the &#8220;after&#8221; part.</p>

<p>Ugly? Oh yeaaaah&#8230; Pretty brutal rummaging around with another objects private parts like that.</p>

<p>Maybe it&#8217;s time somebody teaches Rails Core what &#8220;around&#8221; really means&#8230;</p>]]></content:encoded>
	</item>
</channel>
</rss>
