<?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>Hank Beaver &#187; self Rails introspection meta</title>
	<atom:link href="http://www.hankbeaver.com/index.php/tag/self-rails-introspection-meta/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hankbeaver.com</link>
	<description>Open-source, Internet technologist who works for MaxMedia located in Atlanta, GA, USA</description>
	<lastBuildDate>Tue, 09 Aug 2011 18:20:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Mixin Module Madness &#8212; why self ain&#8217;t really self</title>
		<link>http://www.hankbeaver.com/index.php/2008/04/01/mixin-module-madness-why-self-aint-really-self/</link>
		<comments>http://www.hankbeaver.com/index.php/2008/04/01/mixin-module-madness-why-self-aint-really-self/#comments</comments>
		<pubDate>Tue, 01 Apr 2008 20:11:15 +0000</pubDate>
		<dc:creator>hbeaver</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[self Rails introspection meta]]></category>

		<guid isPermaLink="false">http://1000fires.com/wordpress/?p=39</guid>
		<description><![CDATA[This all came up b/c I wanted to write a shared mixin module to have attachment_fu ready actions for all my controllers that have attachments. No need to put that crap in every controller. So in a mixin module when you want to do some fun reflection/introspection like so:
&#8230;
    @this_obj = self.controller_name.classify.constantize.find_safe
(id,logged_in_user.id)
&#8230;
In [...]]]></description>
			<content:encoded><![CDATA[<p>This all came up b/c I wanted to write a shared mixin module to have attachment_fu ready actions for all my controllers that have attachments. No need to put that crap in every controller. So in a mixin module when you want to do some fun reflection/introspection like so:</p>
<p>&#8230;</p>
<pre>    @this_obj = self.controller_name.classify.constantize.find_safe
(id,logged_in_user.id)</pre>
<p>&#8230;</p>
<p>In Dev this worked great. Tests were good, my mostly view/template developer partner, approved. Deploy to test and WHAMMO!</p>
<p>&#8230;</p>
<pre>    "NameError ("Blogs | ListAll" is not a valid constant name!):</pre>
<p>&#8230;&#8221;</p>
<p>What gives? Mmm, seems when you include a mixin, that is included in a controller. The self.controller_name will report incorrectly in Test and Prod. So I had to adjust the code a little using a new method:</p>
<pre>        @this_obj = self.this_controller_name.classify.constantize.find_safe(
id,logged_in_user.id)</pre>
<p>Below is the method(which is basically David&#8217;s code for controller_name).</p>
<pre>###############################</pre>
<pre>#This method is here b/c it is apparent that Rails
#ActionController.controller_name</pre>
<pre># is unreliable in Test and Production for some reason.</pre>
<pre># attachment_symbol_name: Blogs | List_all_attachments</pre>
<pre># attachment_model ERROR: "Blogs | ListAllAttachment"
#is not a valid constant name</pre>
<pre>###############################</pre>
<pre>def this_controller_name</pre>
<pre>    self_class = self.class.to_s.sub(/Controller$/, '').underscore</pre>
<pre>end</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.hankbeaver.com/index.php/2008/04/01/mixin-module-madness-why-self-aint-really-self/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

