<?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>The Curmudgeoclast &#187; rails</title>
	<atom:link href="http://techblog.daveastels.com/tag/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://techblog.daveastels.com</link>
	<description>This sucks, wouldn&#039;t it be cool if...?</description>
	<lastBuildDate>Mon, 18 Jan 2010 22:30:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>I&#8217;m back</title>
		<link>http://techblog.daveastels.com/2009/05/10/im-back/</link>
		<comments>http://techblog.daveastels.com/2009/05/10/im-back/#comments</comments>
		<pubDate>Sun, 10 May 2009 21:16:24 +0000</pubDate>
		<dc:creator>dastels</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[personal]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://techblog.daveastels.com/?p=312</guid>
		<description><![CDATA[As I&#8217;ve mentioned on Twitter &#38; Facebook, I&#8217;m back to doing Ruby &#38; Rails fulltime.
Joining Google took me out of the Rails community &#38; largely out of the Ruby community.  At least until very recently when I joined a Rails project (yes, at Google.. who&#8217;da thought).
As noted on my blog last spring, I had [...]]]></description>
			<content:encoded><![CDATA[<p>As I&#8217;ve mentioned on Twitter &amp; Facebook, I&#8217;m back to doing Ruby &amp; Rails fulltime.</p>
<p>Joining Google took me out of the Rails community &amp; largely out of the Ruby community.  At least until very recently when I joined a Rails project (yes, at Google.. who&#8217;da thought).</p>
<p>As noted on my blog last spring, I had the rug pulled out from under me with a sudden onset of diabetes.</p>
<p>With all that I pretty much pulled an Austin Powers and went into cold storage for a year &amp; a half.</p>
<p>Well, I&#8217;ve thawed out and am back at it&#8230; Ruby, Rails, and hanging with peeps at conferences.  Look for me on speaker lists before too much longer.</p>
<p>After GoGaRuCo and RailsConf, I&#8217;m back, motivated, and enthused like never before.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.daveastels.com/2009/05/10/im-back/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RSpec is a hit, who&#8217;d o&#8217; thought?</title>
		<link>http://techblog.daveastels.com/2009/01/09/rspec-is-a-hit-whod-o-thought/</link>
		<comments>http://techblog.daveastels.com/2009/01/09/rspec-is-a-hit-whod-o-thought/#comments</comments>
		<pubDate>Sat, 10 Jan 2009 02:14:30 +0000</pubDate>
		<dc:creator>dastels</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://techblog.daveastels.com/?p=298</guid>
		<description><![CDATA[Well, RSpec is doing well.  A couple things of note recently:

part of the install on hivelogic&#8217;s rails install instructions
clear majority favorite on a recent twtpoll:

 
with merb being rolled into Rails, there&#8217;s speculation that RSpec will be supported by Rails out of the box&#8230; that&#8217;d be cool

]]></description>
			<content:encoded><![CDATA[<p>Well, RSpec is doing well.  A couple things of note recently:</p>
<ul>
<li>part of the install on <a href="http://danbenjamin.com/articles/2008/02/ruby-rails-leopard" target="blank">hivelogic&#8217;s rails install instructions</a></li>
<li>clear majority favorite on a <a href="http://twtpoll.com/r/zhh2fm" target="blank">recent twtpoll</a>:<br />
<script src="http://twtpoll.com/js/badge.js" type="text/javascript"></script><br />
 <script src="http://twtpoll.com/badge/r/?twt=zhh2fm&amp;s=200" type="text/javascript"></script></li>
<li>with merb being rolled into Rails, there&#8217;s speculation that RSpec will be supported by Rails out of the box&#8230; that&#8217;d be cool</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://techblog.daveastels.com/2009/01/09/rspec-is-a-hit-whod-o-thought/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Rumble project reports</title>
		<link>http://techblog.daveastels.com/2007/09/11/rails-rumble-project-reports/</link>
		<comments>http://techblog.daveastels.com/2007/09/11/rails-rumble-project-reports/#comments</comments>
		<pubDate>Tue, 11 Sep 2007 09:18:05 +0000</pubDate>
		<dc:creator>dastels</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails rumble]]></category>

		<guid isPermaLink="false">http://techblog.daveastels.com/?p=32</guid>
		<description><![CDATA[The stats for our project:
 
+----------------------+-------+-------+---------+---------+-----+-------+
&#124; Name                 &#124; Lines &#124;   LOC &#124; Classes &#124; Methods &#124; M/C &#124; LOC/M &#124;
+----------------------+-------+-------+---------+---------+-----+-------+
&#124; Controllers          &#124;    70 &#124;   [...]]]></description>
			<content:encoded><![CDATA[<p>The stats for our project:</p>
<p> </p>
<pre>+----------------------+-------+-------+---------+---------+-----+-------+
| Name                 | Lines |   LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Controllers          |    70 |    55 |       2 |       6 |   3 |     7 |
| Helpers              |     6 |     4 |       0 |       0 |   0 |     0 |
| Models               |   891 |   734 |      13 |     110 |   8 |     4 |
| Libraries            |     0 |     0 |       0 |       0 |   0 |     0 |
| Model specs          |  2283 |  1835 |       0 |       0 |   0 |     0 |
| View specs           |     0 |     0 |       0 |       0 |   0 |     0 |
| Controller specs     |     0 |     0 |       0 |       0 |   0 |     0 |
| Helper specs         |     0 |     0 |       0 |       0 |   0 |     0 |
+----------------------+-------+-------+---------+---------+-----+-------+
| Total                |  3250 |  2628 |      15 |     116 |   7 |    20 |
+----------------------+-------+-------+---------+---------+-----+-------+
  Code LOC: 793     Test LOC: 1835     Code to Test Ratio: 1:2.3</pre>
<p> </p>
<p>A few things to notice:</p>
<ul>
<li>very &#8220;rails&#8221; light&#8230; small controller&#8230; very literally a controller.. all the action happens in the models,</li>
<li>all the specs are for model classes, the controller &amp; view do very little.. although the controller could probably do with a few specs, and</li>
<li>there&#8217;s over twice as much code in the specs than in the working classes.</li>
</ul>
<p>The spec run:</p>
<p> </p>
<pre>$rake spec
(in /Users/dastels/Projects/Ruby-Projects/merlin/trunk)
..........................................................................
..........................................................................
..........................................................................
........................................................
Finished in 62.891545 seconds
278 examples, 0 failures</pre>
<p> </p>
<p>and the coverage report:</p>
<table border="0">
<tbody>
<tr>
<td><img src="http://daveastels.com/wp-content/uploads/2007/09/safariscreensnapz001.png" border="0" alt="SafariScreenSnapz001.png" width="600" /></td>
</tr>
<tr>
<td>Note that echo was under development and actually didn&#8217;t get finished in time.  Also we ran out of time before getting to mindbender.</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://techblog.daveastels.com/2007/09/11/rails-rumble-project-reports/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A hell of a way to spend a weekend</title>
		<link>http://techblog.daveastels.com/2007/09/11/a-hell-of-a-way-to-spend-a-weekend/</link>
		<comments>http://techblog.daveastels.com/2007/09/11/a-hell-of-a-way-to-spend-a-weekend/#comments</comments>
		<pubDate>Tue, 11 Sep 2007 07:11:04 +0000</pubDate>
		<dc:creator>dastels</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails rumble]]></category>

		<guid isPermaLink="false">http://techblog.daveastels.com/?p=34</guid>
		<description><![CDATA[Rails Rumble &#8216;07 is over.
It was a total good time.We didn&#8217;t get as much done on our app as we had hoped, but what we got done turned out as well as we could have hoped.I was on the IRC channel the whole time pretty much, which provided a nice sideline.  The whole thing [...]]]></description>
			<content:encoded><![CDATA[<p>Rails Rumble &#8216;07 is over.</p>
<p>It was a total good time.We didn&#8217;t get as much done on our app as we had hoped, but what we got done turned out as well as we could have hoped.I was on the IRC channel the whole time pretty much, which provided a nice sideline.  The whole thing had a strong co-opatition feel.  There was a great group of people involved.</p>
<p>A big THANK YOU to the sponsors, the organisers, the other teams, and mostly to my teammate, <a href="http://www.nancyblenkhorn.com/" target="_blank">Nancy</a>.</p>
<p>We ran into some interesting technical issues in the course of the 48 hours, which I&#8217;ll be writing about over the next few days.For those interested, or just with voyeristic tendancies (ain&#8217;t the web great), there&#8217;s a <a href="http://flickr.com/groups/railsrumble/pool/" target="_blank">flickr pool</a>, and I&#8217;ve posted some pics in my .mac <a href="http://gallery.mac.com/dastels#100189&amp;bgcolor=black" target="_blank">gallery</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.daveastels.com/2007/09/11/a-hell-of-a-way-to-spend-a-weekend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rumbling away</title>
		<link>http://techblog.daveastels.com/2007/09/09/rumbling-away/</link>
		<comments>http://techblog.daveastels.com/2007/09/09/rumbling-away/#comments</comments>
		<pubDate>Sun, 09 Sep 2007 08:37:03 +0000</pubDate>
		<dc:creator>dastels</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails rumble]]></category>

		<guid isPermaLink="false">http://techblog.daveastels.com/?p=36</guid>
		<description><![CDATA[We&#8217;re nearing the half way point of the Rails Rumble.. 1 day, 2 hours, 24 minutes remaining as I write this.  We&#8217;ve been taking some photos that I&#8217;ve been posting at my .Mac web gallery.
]]></description>
			<content:encoded><![CDATA[<p>We&#8217;re nearing the half way point of the Rails Rumble.. 1 day, 2 hours, 24 minutes remaining as I write this.  We&#8217;ve been taking some photos that I&#8217;ve been posting at <a href="http://gallery.mac.com/dastels#100189&amp;bgcolor=black">my .Mac web gallery</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.daveastels.com/2007/09/09/rumbling-away/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Rumble is this weekend</title>
		<link>http://techblog.daveastels.com/2007/09/07/rails-rumble-is-this-weekend/</link>
		<comments>http://techblog.daveastels.com/2007/09/07/rails-rumble-is-this-weekend/#comments</comments>
		<pubDate>Sat, 08 Sep 2007 00:36:04 +0000</pubDate>
		<dc:creator>dastels</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails rumble]]></category>

		<guid isPermaLink="false">http://techblog.daveastels.com/?p=38</guid>
		<description><![CDATA[We&#8217;re getting prepped for the Rails Rumble.  Nancy &#38; I have entered as a team.  The kids have been told they&#8217;re on their own for the weekend.  This is going to be a great bit of fun.
]]></description>
			<content:encoded><![CDATA[<p>We&#8217;re getting prepped for the Rails Rumble.  Nancy &amp; I have entered as a team.  The kids have been told they&#8217;re on their own for the weekend.  This is going to be a great bit of fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.daveastels.com/2007/09/07/rails-rumble-is-this-weekend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Rumble</title>
		<link>http://techblog.daveastels.com/2007/08/15/rails-rumble/</link>
		<comments>http://techblog.daveastels.com/2007/08/15/rails-rumble/#comments</comments>
		<pubDate>Wed, 15 Aug 2007 11:05:02 +0000</pubDate>
		<dc:creator>dastels</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails rumble]]></category>

		<guid isPermaLink="false">http://techblog.daveastels.com/?p=40</guid>
		<description><![CDATA[



The 2007 48 hour Rails coding competition has been announced.  Check it out.  Now we just need a good application idea.



]]></description>
			<content:encoded><![CDATA[<table border="0">
<tbody>
<tr>
<td><img src="http://daveastels.com/wp-content/uploads/2007/08/railsrumble-black-160.png" border="0" alt="railsrumble_black_160.png" width="160" height="160" align="right" /></td>
<td>The 2007 48 hour Rails coding competition has been announced.  <a href="http://railsrumble.com/">Check it out</a>.  Now we just need a good application idea.</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://techblog.daveastels.com/2007/08/15/rails-rumble/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RSpec Autotest now a Rails Plugin</title>
		<link>http://techblog.daveastels.com/2007/03/30/rspec-autotest-now-a-rails-plugin/</link>
		<comments>http://techblog.daveastels.com/2007/03/30/rspec-autotest-now-a-rails-plugin/#comments</comments>
		<pubDate>Fri, 30 Mar 2007 07:30:02 +0000</pubDate>
		<dc:creator>dastels</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rspec]]></category>

		<guid isPermaLink="false">http://techblog.daveastels.com/?p=42</guid>
		<description><![CDATA[RSpec Autotest now a Rails Plugin:
&#8220;Posted by Nick Sieger Wed, 15 Nov 2006 15:46:00 GMT
Inspired by a posting on the RSpec list and recent comments stating that my Auto RSpec hack wasn’t working, I’ve bitten the bullet and upgraded to RSpec 0.7.2, and made rspec_autotest a plugin in the process. So, here are the necessary [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p><a href="http://blog.nicksieger.com/articles/2006/11/15/rspec-autotest-now-a-rails-plugin">RSpec Autotest now a Rails Plugin</a>:</p>
<p>&#8220;Posted by Nick Sieger Wed, 15 Nov 2006 15:46:00 GMT</p>
<p>Inspired by a posting on the RSpec list and recent comments stating that my Auto RSpec hack wasn’t working, I’ve bitten the bullet and upgraded to RSpec 0.7.2, and made rspec_autotest a plugin in the process. So, here are the necessary incantations to auto-rspec your project.&#8221;</p></blockquote>
<p>OK, so I&#8217;m a bit behind on RSpec developments.  But this plugin makes a world of difference when using rspec.</p>
<p>While Nick mentions rspec 0.7.2 in the post, I&#8217;m using it with the latest (pre-trunk) 0.9.0 without any issues.</p>
<p>If you use rspec (with rails or not.. see <a href="http://blog.nicksieger.com/articles/2007/01/30/rspec-autotest-for-standalone-projects">rspec-autotest-for-standalone-projects</a>) you should be using this plugin!</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.daveastels.com/2007/03/30/rspec-autotest-now-a-rails-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using TinyMCE with Rails/AJAX</title>
		<link>http://techblog.daveastels.com/2006/10/29/using-tinymce-with-rails-ajax/</link>
		<comments>http://techblog.daveastels.com/2006/10/29/using-tinymce-with-rails-ajax/#comments</comments>
		<pubDate>Sun, 29 Oct 2006 19:56:00 +0000</pubDate>
		<dc:creator>dastels</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://techblog.daveastels.com/?p=56</guid>
		<description><![CDATA[Our current project is basically a very structured (i.e. niche/focused/custom) content management system.  There are a few places where we want to give the client the ability to edit some HTML page content.  The client is tech-savvy, but not in the  &#8220;I enjoy slinging HTML&#8221; way.  Ergo, we needed WYSIWYG HTML [...]]]></description>
			<content:encoded><![CDATA[<p>Our current project is basically a very structured (i.e. niche/focused/custom) content management system.  There are a few places where we want to give the client the ability to edit some HTML page content.  The client is tech-savvy, but not in the  &#8220;I enjoy slinging HTML&#8221; way.  Ergo, we needed WYSIWYG HTML editing capability.  After some research we decided that TinyMCE was the way to go.  We just had to make it work the way we wanted it to.</p>
<p>Here are my notes on getting <a href="http://tinymce.moxiecode.com/">TinyMCE</a> working nicely in a Rails/AJAX environment.</p>
<p>Start by grabbing the rails plugin (and read the material) from <a href="http://wiki.rubyonrails.org/rails/pages/HowToUseTinyMCE">here</a> and install it as per the instructions.</p>
<p>Allowable options to uses_tiny_mce are documented <a href="http://tinymce.moxiecode.com/tinymce/docs/reference_configuration.html">here</a>&#8230; there are lots of them</p>
<p>I figured that having followed the directions in the above, my work was over.  In fact it was just beginning.  The above will work fine if you have a page, with a textarea that you want to be WYSIWYG.   Our requirements were a bit more involved.  The textarea in question was in a partial that was rendered via a remote updater call (via a link_to_remote in a list on the page).  The main issue here is that the textarea didn&#8217;t exist when the page was rendered&#8230; so TinyMCE had to be hooked up to it later&#8230; when it was injected into the DOM tree.  Some digging through support forums and I found what I needed.  This required a bit of java script in the partial&#8230; <strong>after</strong> the textarea:</p>
<blockquote>
<pre>&lt;%= form_remote_tag :url =&gt; {:action =&gt; 'edit_page', :id =&gt; @page},
                    :before =&gt; "tinyMCE.triggerSave(true,true)" %&gt;
  &lt;b&gt;Page Content:&lt;/b&gt;&lt;br /&gt;
  &lt;%= text_area :page, :content, :rows =&gt; 15, :cols =&gt; 150 %&gt;
  &lt;br /&gt;&lt;br /&gt;
  &lt;%= submit_tag "Update" %&gt;
  &lt;script type="text/javascript"&gt;
  //&lt;![CDATA[
    tinyMCE.execCommand('mceAddControl', true, 'page_content');
  //]]&gt;
  &lt;/script&gt;
&lt;%= end_form_tag %&gt;</pre>
</blockquote>
<p>The next issue was getting the contents out of TinyMCE and accessible to the parameter construction for the remote call.  After a bit of research I ended up with the following:</p>
<blockquote>
<pre>&lt;%= form_remote_tag :url =&gt; {:action =&gt; 'edit_page', :id =&gt; @page},
                    :before =&gt; "tinyMCE.triggerSave(true,true)" %&gt;</pre>
</blockquote>
<p>Normally the save is trigger by a page unload, I needed to force it to happen before the remote call happened.  Putting the call to force (aka trigger) the save in the <code>:before</code> script of the form submission remote call worked great.  So now I had a bigger problem.  TinyMCE was getting hooked up to the textarea.  If the user picked another page item from the list, the div would be refilled with a different rendering of the partial&#8230; with a different textarea node.  The old textarea would be gone&#8230; out from under TinyMCE.  I needed a way to reconnect to the new textarea.  More digging turned up <a href="http://www.rorlach.de/mediawiki/samples/sample009.php">this example</a>.  It gave me the final bit of the puzzle.  My final solution includes the following in <code>application.js</code>:</p>
<blockquote>
<pre>bTextareaWasTinyfied = false; //this should be global, could be stored in a cookie...

function setTextareaToTinyMCE(sEditorID) {
	var oEditor = document.getElementById(sEditorID);
	if(oEditor &amp;&amp; !bTextareaWasTinyfied) {
		tinyMCE.execCommand('mceAddControl', true, sEditorID);
		bTextareaWasTinyfied = true;
	}
	return;
}

function unsetTextareaToTinyMCE(sEditorID) {
	var oEditor = document.getElementById(sEditorID);
	if(oEditor &amp;&amp; bTextareaWasTinyfied) {
		tinyMCE.execCommand('mceRemoveControl', true, sEditorID);
		bTextareaWasTinyfied = false;
	}
	return;
}</pre>
</blockquote>
<p>These two functions are used to disconnect from an existing textarea and reconnect to the newly rendered one.  In the list item that causes the rendering:</p>
<blockquote>
<pre>&lt;%= link_to_remote "&lt;span class=\"listTitle\"&gt;#{page.title}&lt;/span&gt;",
                   {:update =&gt; "editPage",
                    :url =&gt; {:action =&gt; :get_page, :id =&gt; page},
                    :before =&gt; "Effect.Fade('editPage',
                                            {duration: 0.25,
                                             queue: 'end',
                                             afterFinish: function(effect) {
                                               unsetTextareaToTinyMCE('page_content')}})",
                    :complete =&gt; "Effect.Appear('editPage', {duration: 0.5, queue: 'end'})"},
                    :title =&gt; "Edit #{page.title}"  %&gt;</pre>
</blockquote>
<p>To avoid visual weirdness the <em>disconnect</em> is delayed until the fade has completed.  Once the new version of the partial has been loaded, it&#8217;s faded back in.  The relavant bit of the partial is here:</p>
<blockquote>
<pre>&lt;%= form_remote_tag :url =&gt; {:action =&gt; 'edit_page', :id =&gt; @page},
                    :before =&gt; "tinyMCE.triggerSave(true,true)" %&gt;
  &lt;b&gt;Page Content:&lt;/b&gt;&lt;br /&gt;
  &lt;%= text_area :page, :content, :rows =&gt; 15, :cols =&gt; 150 %&gt;
  &lt;br /&gt;&lt;br /&gt;
  &lt;%= submit_tag "Update" %&gt;
  &lt;script type="text/javascript"&gt;
  //&lt;![CDATA[
    setTextareaToTinyMCE('page_content');
  //]]&gt;
  &lt;/script&gt;
&lt;%= end_form_tag %&gt;</pre>
</blockquote>
<p>The last thing was to add a Done/Cancel button to the form:</p>
<blockquote>
<pre>&lt;input type="button"
       value="Done"
       onclick="Effect.Fade('editPage',
                            {duration: 0.25,
                             queue: 'end',
                             afterFinish: function(effect) {
                               unsetTextareaToTinyMCE('page_content')
                             }})" /&gt;</pre>
</blockquote>
<p>Now I have a WYSIWYG textarea in a partial that&#8217;s rendered via a remote call.. and it all works smoothly and exactly as required.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.daveastels.com/2006/10/29/using-tinymce-with-rails-ajax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Role Based Authentication from Rails Recipes. Part 2</title>
		<link>http://techblog.daveastels.com/2006/08/30/role-based-authentication-from-rails-recipes-part-2/</link>
		<comments>http://techblog.daveastels.com/2006/08/30/role-based-authentication-from-rails-recipes-part-2/#comments</comments>
		<pubDate>Wed, 30 Aug 2006 06:19:00 +0000</pubDate>
		<dc:creator>dastels</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://techblog.daveastels.com/?p=76</guid>
		<description><![CDATA[Once I had the user roles code in place, working, and cleaned up, I decided to extend it by allowing regular expressions in the rights instead of literal strings (for controller &#38; action names).  Whether I stick with this going forward, who knows&#8230; but it&#8217;s convenient for development.  Instead of separate rights for [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.daveastels.com/articles/2006/08/29/role-based-authentication-from-rails-recipes-part-1">Once I had the user roles code in place, working, and cleaned up</a>, I decided to extend it by allowing regular expressions in the rights instead of literal strings (for controller &amp; action names).  Whether I stick with this going forward, who knows&#8230; but it&#8217;s convenient for development.  Instead of separate rights for each action on a controller I can specify .* as the action to have the right apply to all actions for a controller.</p>
<p>Recall that I ended up with the core of the rights checking code actually in the <code>Right</code> class:</p>
<blockquote><p><code></p>
<pre>class Right &lt; ActiveRecord::Base
  has_and_belongs_to_many :roles

  def has_right_for?(action_name, controller_name)
    action == action_name &amp;&amp; controller == controller_name
  end
end</pre>
<p></code></p>
<p> </p></blockquote>
<p>My first step was to wrap <code>Right</code>s attributes in a <code>Regexp</code> and do a match with the requested controller/action names:</p>
<blockquote><p><code></p>
<pre>class Right &lt; ActiveRecord::Base
  has_and_belongs_to_many :roles

  def has_right_for?(action_name, controller_name)
    get_action_regex.match(action_name) &amp;&amp; get_controller_regex.match(controller_name)
  end

  def get_action_regex
    Regexp.new(action)
  end

  def get_controller_regex
    Regexp.new(controller)
  end
end</pre>
<p></code></p>
<p> </p></blockquote>
<p>It might be a case of premature optimization, but the <code>Regexp</code>s can easily be cached since they are nicely encapsulated:</p>
<blockquote><p><code></p>
<pre>class Right &lt; ActiveRecord::Base
  has_and_belongs_to_many :roles

  def has_right_for?(action_name, controller_name)
    get_action_regex.match(action_name) &amp;&amp; get_controller_regex.match(controller_name)
  end

  def get_action_regex
    @action_regex || (@action_regex = Regexp.new(action))
  end

  def get_controller_regex
    @controller_regex || (@controller_regex = Regexp.new(controller))
  end

end</pre>
<p></code></p>
<p> </p></blockquote>
<p>Part of the reason I blogged this was as an example of how much easier and obvious an enhancement can be when the code is cleanly (and extremely) refactored.  More importantly, the details of rights can be changed without anything outside of the <code>Right</code> class being aware of it.  If this ability is not one of the core benefits of OO, what is?</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.daveastels.com/2006/08/30/role-based-authentication-from-rails-recipes-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
