<?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: Passing a parameter to a before filter</title>
	<atom:link href="http://blog.aclarke.eu/passing-a-parameter-to-a-before-filter/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.aclarke.eu/passing-a-parameter-to-a-before-filter/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=passing-a-parameter-to-a-before-filter</link>
	<description>random thoughts</description>
	<lastBuildDate>Mon, 26 Dec 2011 07:45:49 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: andrew</title>
		<link>http://blog.aclarke.eu/passing-a-parameter-to-a-before-filter/#comment-7</link>
		<dc:creator>andrew</dc:creator>
		<pubDate>Tue, 20 Jan 2009 17:40:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.aclarke.eu/?p=3#comment-7</guid>
		<description>Hi Cassiano, 
I fixed your comment :) Wordpress was obviously screwing up your previous attempts.
The parameterized_before_filter is great much more thought out than my simple attempt. 
I&#039;m not sure why rails doesn&#039;t provide such a method already as it is pretty useful, i guess though that ruby lets you do it pretty easily anyway if in a non newbie friendly way. If you find out the reason please let me know.</description>
		<content:encoded><![CDATA[<p>Hi Cassiano,<br />
I fixed your comment <img src='http://blog.aclarke.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  WordPress was obviously screwing up your previous attempts.<br />
The parameterized_before_filter is great much more thought out than my simple attempt.<br />
I&#8217;m not sure why rails doesn&#8217;t provide such a method already as it is pretty useful, i guess though that ruby lets you do it pretty easily anyway if in a non newbie friendly way. If you find out the reason please let me know.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cassiano D'Andrea</title>
		<link>http://blog.aclarke.eu/passing-a-parameter-to-a-before-filter/#comment-3</link>
		<dc:creator>Cassiano D'Andrea</dc:creator>
		<pubDate>Tue, 20 Jan 2009 17:09:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.aclarke.eu/?p=3#comment-3</guid>
		<description>Hi. After reading your post I came out with:

&lt;pre&gt;
class ApplicationController &lt; ActionController::Base
  #################################################
  def self.parameterized_before_filter(filter_name, *args)
    options = args.extract_options!

    self.before_filter(options) { &#124;controller&#124; controller.send(filter_name, *args) }
  end

  #################################################
  # Sample usage with 2 parameters.
  parameterized_before_filter :my_filter, &#039;param1&#039;, &#039;param2&#039;, :only =&gt; :create

  #################################################
  # Sample usage passing a hash as a parameter value.
  parameterized_before_filter :my_filter, &#039;param1&#039;, &#039;param2&#039;, 
                                            { :param3 =&gt; :value3 }, :only =&gt; :create

  #################################################
  # The filter itself.
  def my_filter(*args)
    puts args.inspect
  end
end
&lt;/pre&gt;

How do you like it? Why doesn&#039;t Rails provide such method out of the box?

One might also add :parameterized_before_filter directly to ActionController::Base, or even replace the original :before_filter (using :alias_method_chain).

Thanks for sharing the tip.</description>
		<content:encoded><![CDATA[<p>Hi. After reading your post I came out with:</p>
<pre>
class ApplicationController < ActionController::Base
  #################################################
  def self.parameterized_before_filter(filter_name, *args)
    options = args.extract_options!

    self.before_filter(options) { |controller| controller.send(filter_name, *args) }
  end

  #################################################
  # Sample usage with 2 parameters.
  parameterized_before_filter :my_filter, 'param1', 'param2', <img src='http://blog.aclarke.eu/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> nly => :create

  #################################################
  # Sample usage passing a hash as a parameter value.
  parameterized_before_filter :my_filter, 'param1', 'param2',
                                            { :param3 => :value3 }, <img src='http://blog.aclarke.eu/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> nly => :create

  #################################################
  # The filter itself.
  def my_filter(*args)
    puts args.inspect
  end
end
</pre>
<p>How do you like it? Why doesn&#8217;t Rails provide such method out of the box?</p>
<p>One might also add :parameterized_before_filter directly to ActionController::Base, or even replace the original :before_filter (using :alias_method_chain).</p>
<p>Thanks for sharing the tip.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

