<?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>rel=me &#187; Rails</title>
	<atom:link href="http://rel.me/c/ror/feed/" rel="self" type="application/rss+xml" />
	<link>http://rel.me</link>
	<description>programming, objective-c, cocoa, iphone, c</description>
	<lastBuildDate>Mon, 02 Aug 2010 20:09:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Freezing gems with Gem.use_path</title>
		<link>http://rel.me/2008/04/09/freezing-gems-with-gem-use-path/</link>
		<comments>http://rel.me/2008/04/09/freezing-gems-with-gem-use-path/#comments</comments>
		<pubDate>Wed, 09 Apr 2008 17:12:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[gems]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rubygems]]></category>

		<guid isPermaLink="false">/2008/04/09/freezing-gems-with-gem-use-path</guid>
		<description><![CDATA[Edge rails now has gem dependency support built in, with tasks to freeze in vendor/gems. I have tried a bunch of different methods, and things like setting $GEM_HOME or using gemsonrails work well. But lately I have been using the Gem.use_paths method. If you put this in the config/environments rb: Gem.use_paths&#40;nil, &#91; &#34;#{RAILS_ROOT}/vendor/rubygems&#34; &#93;&#41; # [...]]]></description>
			<content:encoded><![CDATA[<p>Edge rails now has <a href="http://ryandaigle.com/articles/2008/4/1/what-s-new-in-edge-rails-gem-dependencies">gem dependency</a> support built in, with tasks to freeze in vendor/gems.</p>
<p>I have tried a bunch of different methods, and things like setting <tt>$GEM_HOME</tt> or using <a href="http://gemsonrails.rubyforge.org/">gemsonrails</a> work well. But lately I have been using the Gem.use_paths method.</p>
<p>If you put this in the config/environments rb:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Gem.<span class="me1">use_paths</span><span class="br0">&#40;</span><span class="kw2">nil</span>, <span class="br0">&#91;</span> <span class="st0">&quot;#{RAILS_ROOT}/vendor/rubygems&quot;</span> <span class="br0">&#93;</span><span class="br0">&#41;</span>
<span class="co1"># Gem.path is now:</span>
<span class="co1"># [&quot;/Users/ghandford/Projects/my_rails_proj/vendor/rubygems&quot;, &quot;/Library/Ruby/Gems/1.8&quot;]</span></pre></div></div>

<p>The vendor/rubygems directory is the same structure as system gems folder:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">  vendor/rubygems/cache
  vendor/rubygems/doc
  vendor/rubygems/gems
  vendor/rubygems/specifications</pre></div></div>

<p>The convention I use is any non-native gems get frozen with the project, and then all the native gems go in the system gem path, which gets you pretty close to clone/checkout and rake setup.</p>
<p>As far as unpacking and install gems, you just use <tt>gem install</tt> with GEM_HOME of your local project:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span class="re2">GEM_HOME</span>=<span class="sy0">`</span><span class="kw3">pwd</span><span class="sy0">`/</span>vendor<span class="sy0">/</span>rubygems gem <span class="kw2">install</span> capitate</pre></div></div>

<p>A benefit of the use_paths method is that you can create scripts in your Rails project that use gems frozen in your project (and not necessarily have to require rails or environment.rb to get at them).</p>
<pre>
./script/my_non_rails_script
</pre>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span class="kw3">require</span> <span class="st0">'rubygems'</span>
  Gem.<span class="me1">use_paths</span><span class="br0">&#40;</span><span class="kw2">nil</span>, <span class="br0">&#91;</span> <span class="kw4">File</span>.<span class="me1">dirname</span><span class="br0">&#40;</span><span class="kw2">__FILE__</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;/../vendor/rubygems&quot;</span> <span class="br0">&#93;</span><span class="br0">&#41;</span></pre></div></div>

<p>Has anyone else tried this before?</p>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2008/04/09/freezing-gems-with-gem-use-path/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>politweets</title>
		<link>http://rel.me/2008/01/10/politweets/</link>
		<comments>http://rel.me/2008/01/10/politweets/#comments</comments>
		<pubDate>Thu, 10 Jan 2008 02:02:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">/2008/01/10/politweets</guid>
		<description><![CDATA[We built another twitter app, this time tracking candidates names. Its called politweets. One #1 referrer today was from 100shiki. I&#8217;ve always been big in Japan. Hopefully this one is a little more relevant than tracking curse words. But I still think the bitch balls&#8216;er is awesome.]]></description>
			<content:encoded><![CDATA[<p>We built another twitter app, this time tracking candidates names. Its called <a href="http://politweets.com">politweets</a>. </p>
<p>One #1 referrer today was from <a href="http://www.100shiki.com/archives/2008/01/twitterpolitweets.html">100shiki</a>. I&#8217;ve always been <a href="http://flickr.com/photos/g4b3/1121701257/">big in Japan</a>.</p>
<p>Hopefully this one is a little more relevant than tracking curse words. But I still think the <a href="http://twittertale.com/search?q=bumblebunny">bitch balls</a>&#8216;er is awesome.</p>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2008/01/10/politweets/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>nginx conf with alternate cache dir</title>
		<link>http://rel.me/2008/01/07/nginx-conf-with-alternate-cache-dir/</link>
		<comments>http://rel.me/2008/01/07/nginx-conf-with-alternate-cache-dir/#comments</comments>
		<pubDate>Mon, 07 Jan 2008 07:25:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Deployment]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">/2008/01/07/nginx-conf-with-alternate-cache-dir</guid>
		<description><![CDATA[Its a good idea to use an alternate cache directory in rails (in your environment.rb): config.action_controller.page_cache_directory = RAILS_ROOT + &#34;/public/cache/&#34; This makes it easier to sweep. To setup nginx to pick up from a rails alternate cache directory like public/cache, I used: if ($http_user_agent ~* &#34;(iPhone&#124;iPod)&#34;) { rewrite ^/$ /iphone break; proxy_pass http://mongrel-pt; break; } [...]]]></description>
			<content:encoded><![CDATA[<p>Its a good idea to use an alternate cache directory in rails (in your environment.rb):</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">config.<span class="me1">action_controller</span>.<span class="me1">page_cache_directory</span> = RAILS_ROOT <span class="sy0">+</span> <span class="st0">&quot;/public/cache/&quot;</span></pre></div></div>

<p>This makes it easier to sweep. To setup nginx to pick up from a rails alternate cache directory like public/cache, I used:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">if ($http_user_agent ~* &quot;(iPhone|iPod)&quot;) {
  rewrite ^/$ /iphone break;
  proxy_pass http://mongrel-pt;
  break;
}
&nbsp;
if (-f $request_filename) {
  break;
}
&nbsp;
if (-f $document_root/cache/$uri/index.html) {
  rewrite (.*) /cache/$1/index.html break;
}
&nbsp;
if (-f $document_root/cache/$uri.html) {
  rewrite (.*) /cache/$1.html break;
}
&nbsp;
if (-f $document_root/cache/$uri) {
  rewrite (.*) /cache/$1 break;
}
&nbsp;
if (!-f $request_filename) {
  proxy_pass http://mongrel-pt;
  break;
}</pre></div></div>

<p>It was a little tricky to figure out to use the $uri variable. The first rewrite is used for iphone requests so it doesn&#8217;t get the non-iphone cached page.</p>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2008/01/07/nginx-conf-with-alternate-cache-dir/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>twittertale.com</title>
		<link>http://rel.me/2007/12/17/twittertale-com/</link>
		<comments>http://rel.me/2007/12/17/twittertale-com/#comments</comments>
		<pubDate>Mon, 17 Dec 2007 23:34:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[twittertale]]></category>

		<guid isPermaLink="false">/2007/12/18/twittertale-com</guid>
		<description><![CDATA[Some friends and I did a twitter thing where we catch tweets with curse words and put them on twittertale.com. Its kind of funny. The backend twitter side is xmpp4r and xmpp4r-simple straight up ruby. And the web side is fresh rails 2.0 happiness. On a side note, if you are doing ruby sans rails [...]]]></description>
			<content:encoded><![CDATA[<p>Some friends and I did a twitter thing where we catch tweets with curse words and put them on <a href="http://twittertale.com">twittertale.com</a>. Its kind of funny. The backend twitter side is <a href="http://home.gna.org/xmpp4r/">xmpp4r</a> and <a href="http://code.google.com/p/xmpp4r-simple/">xmpp4r-simple </a> straight up ruby. And the web side is fresh rails 2.0 happiness.</p>
<p>On a side note, if you are doing ruby sans rails with mysql gem, you need to take care of the character encoding on the connection, which you can do by sending <tt>SET NAMES UTF8;</tt> after connect or I guess by setting the default on connection settings in <tt>my.cnf</tt></p>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2007/12/17/twittertale-com/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>View paths in Rails 2.0</title>
		<link>http://rel.me/2007/12/17/view-paths-in-rails-2-0/</link>
		<comments>http://rel.me/2007/12/17/view-paths-in-rails-2-0/#comments</comments>
		<pubDate>Mon, 17 Dec 2007 17:03:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">/2007/12/17/view-paths-in-rails-2-0</guid>
		<description><![CDATA[New in rails 2.0: ActionController::Base.append_view_path This is useful for loading views from a plugin or gem: ActionController::Base.append_view_path&#40;File.dirname&#40;__FILE__&#41; + &#34;/views&#34;&#41; There is also ActionController::Base.prepend_path.]]></description>
			<content:encoded><![CDATA[<p>New in rails 2.0:</p>
<p><a href="http://api.rubyonrails.org/classes/ActionController/Base.html#M000451">ActionController::Base.append_view_path</a></p>
<p>This is useful for loading views from a plugin or gem:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span class="re2">ActionController::Base</span>.<span class="me1">append_view_path</span><span class="br0">&#40;</span><span class="kw4">File</span>.<span class="me1">dirname</span><span class="br0">&#40;</span><span class="kw2">__FILE__</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;/views&quot;</span><span class="br0">&#41;</span></pre></div></div>

<p>There is also <a href="http://api.rubyonrails.org/classes/ActionController/Base.html#M000439">ActionController::Base.prepend_path.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2007/12/17/view-paths-in-rails-2-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>set_trace_func and filter on regex</title>
		<link>http://rel.me/2007/08/29/trace-with-regex/</link>
		<comments>http://rel.me/2007/08/29/trace-with-regex/#comments</comments>
		<pubDate>Wed, 29 Aug 2007 00:58:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[set_trace_func]]></category>

		<guid isPermaLink="false">/2007/09/03/trace-with-regex</guid>
		<description><![CDATA[I needed to use the trace_func to figure out a bug, and I came up with: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 class Tracer class &#60;&#60; self def on(io = STDERR, [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to use the trace_func to figure out a bug, and I came up with:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt>9<tt>
</tt><strong>10</strong><tt>
</tt>11<tt>
</tt>12<tt>
</tt>13<tt>
</tt>14<tt>
</tt>15<tt>
</tt>16<tt>
</tt>17<tt>
</tt>18<tt>
</tt>19<tt>
</tt><strong>20</strong><tt>
</tt>21<tt>
</tt>22<tt>
</tt>23<tt>
</tt>24<tt>
</tt>25<tt>
</tt>26<tt>
</tt>27<tt>
</tt>28<tt>
</tt>29<tt>
</tt><strong>30</strong><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">  <span class="r">class</span> <span class="cl">Tracer</span><tt>
</tt>    <tt>
</tt>    <span class="r">class</span> &lt;&lt; <span class="cl">self</span><tt>
</tt>      <tt>
</tt>      <span class="r">def</span> <span class="fu">on</span>(io = <span class="co">STDERR</span>, regex = <span class="pc">nil</span>)<tt>
</tt>        set_trace_func proc { |event, file, line, id, binding, classname|<tt>
</tt>          <span class="r">if</span> !regex.blank?<tt>
</tt>            s = format(<span class="s"><span class="dl">&quot;</span><span class="k">%8s %s:%-2d %10s %8s</span><span class="ch">\n</span><span class="dl">&quot;</span></span>, event, file, line, id, classname)<tt>
</tt>            io.printf(s) <span class="r">if</span> s =~ regex            <tt>
</tt>          <span class="r">else</span><tt>
</tt>            io.printf(<span class="s"><span class="dl">&quot;</span><span class="k">%8s %s:%-2d %10s %8s</span><span class="ch">\n</span><span class="dl">&quot;</span></span>, event, file, line, id, classname)<tt>
</tt>          <span class="r">end</span><tt>
</tt>        }<tt>
</tt>      <span class="r">end</span><tt>
</tt>    <tt>
</tt>      <span class="r">def</span> <span class="fu">off</span><tt>
</tt>        set_trace_func <span class="pc">nil</span><tt>
</tt>      <span class="r">end</span><tt>
</tt>    <tt>
</tt>      <span class="r">def</span> <span class="fu">trace</span>(io = <span class="co">STDERR</span>, regex = <span class="pc">nil</span>, &amp;block)<tt>
</tt>        on(io, regex)<tt>
</tt>        retval = <span class="r">yield</span> <span class="r">if</span> block_given?<tt>
</tt>        off      <tt>
</tt>        retval<tt>
</tt>      <span class="r">end</span><tt>
</tt>      <tt>
</tt>    <span class="r">end</span><tt>
</tt>  <span class="r">end</span><tt>
</tt>  <tt>
</tt><span class="r">end</span></pre>
</td>
</tr>
</table>
<p>Then <tt>Tracer.trace { 1 + 1 }</tt> or specify a regex filter:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">&gt;&gt; <span class="co">Tracer</span>.trace(<span class="co">STDERR</span>, <span class="rx"><span class="dl">/</span><span class="k">Fixnum</span><span class="dl">/</span></span>) { <span class="i">1</span> + <span class="i">1</span> }<tt>
</tt>  c-call (irb):<span class="i">2</span>           +   <span class="co">Fixnum</span><tt>
</tt>c-<span class="r">return</span> (irb):<span class="i">2</span>           +   <span class="co">Fixnum</span><tt>
</tt>=&gt; <span class="i">2</span><tt>
</tt>&gt;&gt; </pre>
</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2007/08/29/trace-with-regex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GC and ObjectSpace</title>
		<link>http://rel.me/2007/08/24/gc-and-objectspace/</link>
		<comments>http://rel.me/2007/08/24/gc-and-objectspace/#comments</comments>
		<pubDate>Fri, 24 Aug 2007 17:01:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[gc]]></category>
		<category><![CDATA[objectspace]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">/2007/09/05/gc-and-objectspace</guid>
		<description><![CDATA[I saw this at the Rails Edge conference and thought it was cool; aside from its really expensive to implement in JRuby. 1 2 3 4 5 6 7 8 9 10 &#62;&#62; GC.disable =&#62; false &#62;&#62; instances = 0 =&#62; 0 &#62;&#62; ObjectSpace.each_object(Artist) { &#124;a&#124; instances += 1 } =&#62; 0 &#62;&#62; Artist.find(:all, :limit [...]]]></description>
			<content:encoded><![CDATA[<p>I saw this at the Rails Edge conference and thought it was cool; aside from its <a href="http://ola-bini.blogspot.com/2007/07/objectspace-to-have-or-not-to-have.html">really expensive to implement in JRuby</a>.</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt>9<tt>
</tt><strong>10</strong><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">&gt;&gt; <span class="co">GC</span>.disable<tt>
</tt>=&gt; <span class="pc">false</span><tt>
</tt>&gt;&gt; instances = <span class="i">0</span><tt>
</tt>=&gt; <span class="i">0</span><tt>
</tt>&gt;&gt;  <span class="co">ObjectSpace</span>.each_object(<span class="co">Artist</span>) { |a| instances += <span class="i">1</span> }<tt>
</tt>=&gt; <span class="i">0</span><tt>
</tt>&gt;&gt; <span class="co">Artist</span>.find(<span class="sy">:all</span>, <span class="sy">:limit</span> =&gt; <span class="i">5</span>)<tt>
</tt>=&gt; [<span class="c">#&lt;Artist:0x327d348 @attributes={....</span><tt>
</tt>&gt;&gt;  <span class="co">ObjectSpace</span>.each_object(<span class="co">Artist</span>) { |a| instances += <span class="i">1</span> }<tt>
</tt>=&gt; <span class="i">5</span></pre>
</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2007/08/24/gc-and-objectspace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Markup, CSS and Helper cataloging (Part deux)</title>
		<link>http://rel.me/2007/06/25/markup-css-and-helper-cataloging-part-deux/</link>
		<comments>http://rel.me/2007/06/25/markup-css-and-helper-cataloging-part-deux/#comments</comments>
		<pubDate>Mon, 25 Jun 2007 15:37:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[erb]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">/2007/09/03/markup-css-and-helper-cataloging-part-deux</guid>
		<description><![CDATA[I should be using ERB instead of eval. But because you can&#8217;t use &#60;% inside a string block in your view (that I can figure out; &#60;&#60;EOF didn&#8217;t seem to be working in a template). And if you don&#8217;t want to specify the code string in your controller you can use [% ... %]. Here [...]]]></description>
			<content:encoded><![CDATA[<p>I should be using ERB instead of eval. But because you can&#8217;t use &lt;% inside a string block in your view (that I can figure out; &lt;&lt;EOF didn&#8217;t seem to be working in a template). And if you don&#8217;t want to specify the code string in your controller you can use [% ...  %]. Here is the source I am using for our code helper now:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt>9<tt>
</tt><strong>10</strong><tt>
</tt>11<tt>
</tt>12<tt>
</tt>13<tt>
</tt>14<tt>
</tt>15<tt>
</tt>16<tt>
</tt>17<tt>
</tt>18<tt>
</tt>19<tt>
</tt><strong>20</strong><tt>
</tt>21<tt>
</tt>22<tt>
</tt>23<tt>
</tt>24<tt>
</tt>25<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">  <span class="r">def</span> <span class="fu">erb_code</span>(code) <tt>
</tt>    <span class="co">ERB</span>.new(code).result(binding)    <tt>
</tt>  <span class="r">end</span><tt>
</tt>  <tt>
</tt>  <span class="r">def</span> <span class="fu">render_code</span>(code, options = {}) <tt>
</tt>    %{ &lt;pre <span class="r">class</span>=<span class="s"><span class="dl">&quot;</span><span class="k">helper</span><span class="dl">&quot;</span></span>&gt;<span class="er">\</span>n&lt;code <span class="r">class</span>=<span class="s"><span class="dl">&quot;</span><span class="k">ruby</span><span class="dl">&quot;</span></span>&gt;<span class="er">\</span>n<span class="c">#{h(code)}\n&lt;/code&gt;\n&lt;/pre&gt; }</span><tt>
</tt>  <span class="r">end</span><tt>
</tt>  <tt>
</tt>  <span class="r">def</span> <span class="fu">render_markup</span>(html)<tt>
</tt>    doc = <span class="co">REXML</span>::<span class="co">Document</span>.new(html)<tt>
</tt>    markup = <span class="s"><span class="dl">&quot;</span><span class="dl">&quot;</span></span><tt>
</tt>    doc.write(markup, <span class="i">2</span>)<tt>
</tt>    <tt>
</tt>    <span class="s"><span class="dl">%{</span><span class="k"> &lt;pre class=&quot;markup&quot;&gt;</span><span class="ch">\n</span><span class="k">&lt;code class=&quot;html&quot;&gt;</span><span class="ch">\n</span><span class="il"><span class="idl">#{</span>h(markup)<span class="idl">}</span></span><span class="ch">\n</span><span class="k">&lt;/code&gt;</span><span class="ch">\n</span><span class="k">&lt;/pre&gt;</span><span class="ch">\n</span><span class="k"> </span><span class="dl">}</span></span>    <tt>
</tt>  <span class="r">end</span><tt>
</tt>  <tt>
</tt>  <span class="r">def</span> <span class="fu">render_eval</span>(html)<tt>
</tt>    <span class="s"><span class="dl">%{</span><span class="k"> &lt;div class=&quot;eval&quot;&gt;</span><span class="il"><span class="idl">#{</span>html<span class="idl">}</span></span><span class="k">&lt;/div&gt; </span><span class="dl">}</span></span><tt>
</tt>  <span class="r">end</span><tt>
</tt>    <tt>
</tt>  <span class="r">def</span> <span class="fu">code_helper</span>(code)<tt>
</tt>    code.gsub!(<span class="rx"><span class="dl">/</span><span class="ch">\[</span><span class="k">%</span><span class="dl">/</span></span>, <span class="s"><span class="dl">&quot;</span><span class="k">&lt;%</span><span class="dl">&quot;</span></span>).gsub!(<span class="rx"><span class="dl">/</span><span class="k">%</span><span class="ch">\]</span><span class="dl">/</span></span>, <span class="s"><span class="dl">&quot;</span><span class="k">%&gt;</span><span class="dl">&quot;</span></span>)    <tt>
</tt>    html = erb_code(code)<tt>
</tt>    render_code(code) + render_markup(html) + render_eval(html)<tt>
</tt>  <span class="r">end</span></pre>
</td>
</tr>
</table>
<p>Then you can do things like:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">  &lt;<span class="s"><span class="dl">%=</span><span class="k"> code_helper %{ [%</span><span class="dl">=</span></span> rating_field(<span class="sy">:rating</span>, <span class="sy">:effectiveness</span>) %] } %&gt;</pre>
</td>
</tr>
</table>
<p>and you could also dump it in a helper:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt>9<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"><span class="r">def</span> <span class="fu">code_rating_form_field</span> <tt>
</tt>  &lt;&lt;-<span class="co">EOF</span><tt>
</tt>   &lt;<span class="s"><span class="dl">% </span><span class="k">form_for</span><span class="dl"> </span></span><span class="sy">:rating</span>, <span class="iv">@rating2</span> <span class="r">do</span> |f| <span class="s"><span class="dl">%&gt;</span><span class="k"><tt>
</tt>     &lt;%= f.rating_field(:effectiveness) %</span><span class="dl">&gt;</span></span><tt>
</tt>   &lt;<span class="s"><span class="dl">% </span><span class="k">end</span><span class="dl"> </span></span>%&gt;<tt>
</tt>  <span class="co">EOF</span><tt>
</tt><span class="r">end</span><tt>
</tt><tt>
</tt>  <span class="rx"><span class="dl">/</span><span class="dl">/</span></span> <span class="co">And</span> <span class="r">in</span> your view: &lt;<span class="s"><span class="dl">%=</span><span class="k"> code_helper(code_rating_form_field) %&gt;</span></span></pre>
</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2007/06/25/markup-css-and-helper-cataloging-part-deux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Markup, CSS and Helper cataloging</title>
		<link>http://rel.me/2007/06/18/markup-css-and-helper-cataloging/</link>
		<comments>http://rel.me/2007/06/18/markup-css-and-helper-cataloging/#comments</comments>
		<pubDate>Mon, 18 Jun 2007 23:55:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">/2007/09/03/markup-css-and-helper-cataloging</guid>
		<description><![CDATA[At work, we have a catalog of markup and CSS and any ruby helpers. I wrote this helper for it which takes a code string and spits it out, evals it, and provides the eval&#8217;ed html wrapped and indented. The code-highligher does all the highlighting. 1 2 3 4 5 6 7 8 9 10 [...]]]></description>
			<content:encoded><![CDATA[<p>At work, we have a catalog of markup and CSS and any ruby helpers. I wrote this helper for it which takes a code string and spits it out, evals it, and provides the eval&#8217;ed html wrapped and indented. The <a href="http://svn.danwebb.net/external/CodeHighlighter/trunk/">code-highligher</a> does all the highlighting.</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt>9<tt>
</tt><strong>10</strong><tt>
</tt>11<tt>
</tt>12<tt>
</tt>13<tt>
</tt>14<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"><span class="r">def</span> <span class="fu">code_helper</span>(code) <tt>
</tt>   help_block = <span class="s"><span class="dl">%{</span><span class="k"> &lt;pre class=&quot;helper&quot;&gt;</span><span class="ch">\n</span><span class="k">&lt;code class=&quot;ruby&quot;&gt;</span><span class="ch">\n</span><span class="k">&lt;%= </span><span class="il"><span class="idl">#{</span>h(code)<span class="idl">}</span></span><span class="k"> %&gt;</span><span class="ch">\n</span><span class="k">&lt;/code&gt;</span><span class="ch">\n</span><span class="k">&lt;/pre&gt; </span><span class="dl">}</span></span><tt>
</tt>    <tt>
</tt>    result = instance_eval code, <span class="s"><span class="dl">&quot;</span><span class="k">generated code (</span><span class="il"><span class="idl">#{</span><span class="pc">__FILE__</span><span class="idl">}</span></span><span class="k">:</span><span class="il"><span class="idl">#{</span><span class="pc">__LINE__</span><span class="idl">}</span></span><span class="k">)</span><span class="dl">&quot;</span></span><tt>
</tt>    result_block = <span class="s"><span class="dl">%{</span><span class="k"> &lt;div class=&quot;eval&quot;&gt;</span><span class="il"><span class="idl">#{</span>result<span class="idl">}</span></span><span class="k">&lt;/div&gt; </span><span class="dl">}</span></span><tt>
</tt>    <tt>
</tt>    doc = <span class="co">REXML</span>::<span class="co">Document</span>.new(result)<tt>
</tt>    markup = <span class="s"><span class="dl">&quot;</span><span class="dl">&quot;</span></span><tt>
</tt>    doc.write(markup, <span class="i">2</span>)<tt>
</tt>    <tt>
</tt>    markup_block = <span class="s"><span class="dl">%{</span><span class="k"> &lt;pre class=&quot;markup&quot;&gt;</span><span class="ch">\n</span><span class="k">&lt;code class=&quot;html&quot;&gt;</span><span class="ch">\n</span><span class="il"><span class="idl">#{</span>h(markup)<span class="idl">}</span></span><span class="ch">\n</span><span class="k">&lt;/code&gt;</span><span class="ch">\n</span><span class="k">&lt;/pre&gt;</span><span class="ch">\n</span><span class="k"> </span><span class="dl">}</span></span><tt>
</tt>    <tt>
</tt>    <span class="s"><span class="dl">%{</span><span class="k"> </span><span class="il"><span class="idl">#{</span>help_block<span class="idl">}</span></span><span class="k"> </span><span class="il"><span class="idl">#{</span>markup_block<span class="idl">}</span></span><span class="k"> </span><span class="il"><span class="idl">#{</span>result_block<span class="idl">}</span></span><span class="k"> </span><span class="dl">}</span></span><tt>
</tt><span class="r">end</span></pre>
</td>
</tr>
</table>
<p>And usage: </p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">&lt;<span class="s"><span class="dl">%=</span><span class="k"> code_helper %{ will_paginate(@count, @per_page, @page_num, { :extra_param </span><span class="dl">=</span></span>&gt; <span class="s"><span class="dl">&quot;</span><span class="k">extra1</span><span class="dl">&quot;</span></span> }) } %&gt;</pre>
</td>
</tr>
</table>
<p>would display the code, the (escaped) markup that it generates, and then the straight up html.</p>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2007/06/18/markup-css-and-helper-cataloging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Render content in layout</title>
		<link>http://rel.me/2007/05/30/render-content-in-layout/</link>
		<comments>http://rel.me/2007/05/30/render-content-in-layout/#comments</comments>
		<pubDate>Wed, 30 May 2007 16:35:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">/2007/09/03/render-content-in-layout</guid>
		<description><![CDATA[I came up with a hack to render content inside a layout, from the controller: 1 2 3 4 5 6 7 8 9 10 def content_with_layout(content_for_layout, controller, layout = &#34;the_layout&#34;) locals = { :params =&#62; controller.params } template = controller.class.view_class.new(controller.class.view_root, locals, controller) template.instance_variable_set(&#34;@content_for_layout&#34;, content_for_layout) # This might work to get assigns? untested... #template.assigns = [...]]]></description>
			<content:encoded><![CDATA[<p>I came up with a hack to render content inside a layout, from the controller:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt>9<tt>
</tt><strong>10</strong><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">  <span class="r">def</span> <span class="fu">content_with_layout</span>(content_for_layout, controller, layout = <span class="s"><span class="dl">&quot;</span><span class="k">the_layout</span><span class="dl">&quot;</span></span>)<tt>
</tt>    locals = { <span class="sy">:params</span> =&gt; controller.params }<tt>
</tt>    template = controller.class.view_class.new(controller.class.view_root, locals, controller)<tt>
</tt>    template.instance_variable_set(<span class="s"><span class="dl">&quot;</span><span class="k">@content_for_layout</span><span class="dl">&quot;</span></span>, content_for_layout)    <tt>
</tt>    <tt>
</tt>    <span class="c"># This might work to get assigns? untested...</span><tt>
</tt>    <span class="c">#template.assigns = controller.template.instance_variable_get(&quot;@assigns&quot;) </span><tt>
</tt><tt>
</tt>    template.render_file(<span class="s"><span class="dl">&quot;</span><span class="k">layouts/</span><span class="il"><span class="idl">#{</span>layout<span class="idl">}</span></span><span class="dl">&quot;</span></span>, <span class="pc">true</span>)    <tt>
</tt>  <span class="r">end</span>  </pre>
</td>
</tr>
</table>
<p>You have to pass in any locals you want, and if you want the use assigns in your layout you would have to set the template.assigns. There was some plugin to give you extra layouts in the view but I forget what it was called. Anybody know where that is?</p>
<p><strong>Update:</strong> The inside layout is at: <a href="http://fora.pragprog.com/rails-recipes/write-your-own/post/144">http://fora.pragprog.com/rails-recipes/write-your-own/post/144</a></p>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2007/05/30/render-content-in-layout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
