<?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>Mike&#039;s burogu</title>
	<atom:link href="http://www.bsodmike.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bsodmike.com</link>
	<description>The blog of Michael de Silva (bsodmike)</description>
	<lastBuildDate>Mon, 07 Nov 2011 09:43:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Nature Taking a Byte Out of Technology</title>
		<link>http://www.bsodmike.com/2011/11/07/nature-taking-a-byte-out-of-technology/</link>
		<comments>http://www.bsodmike.com/2011/11/07/nature-taking-a-byte-out-of-technology/#comments</comments>
		<pubDate>Mon, 07 Nov 2011 09:43:30 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Gadgets and Tech]]></category>

		<guid isPermaLink="false">http://www.bsodmike.com/?p=686</guid>
		<description><![CDATA[This is the second time in 2011, when nature has reminded us of its divine power. The Fukushima Daiichi nuclear incident in Japan earlier this year, affected much of the NAND RAM supplies in the region impacting the likes of Sony and even Apple. Right now, we learn about the flooding in Thailand and its [...]]]></description>
			<content:encoded><![CDATA[<p>This is the second time in 2011, when nature has reminded us of its divine power.  The Fukushima Daiichi nuclear incident in Japan earlier this year, affected much of the NAND RAM supplies in the region impacting the likes of Sony and even Apple.</p>

<p>Right now, we learn about the <a href="http://www.theverge.com/2011/11/5/2540403/thailand-flood-disaster">flooding in Thailand</a> and its potential effects on HDD supplies.  Prices are being pushed upwards as a result.</p>

<p>I wonder, although sincerely hope not, if the next global crisis will be a result of multi-regional devastation in Asia.  Oh, I hope not&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bsodmike.com/2011/11/07/nature-taking-a-byte-out-of-technology/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails 3.1: Starting the Week on Sunday, as in the Middle East</title>
		<link>http://www.bsodmike.com/2011/10/22/rails-3-1-starting-the-week-on-sunday-as-in-the-middle-east/</link>
		<comments>http://www.bsodmike.com/2011/10/22/rails-3-1-starting-the-week-on-sunday-as-in-the-middle-east/#comments</comments>
		<pubDate>Fri, 21 Oct 2011 21:14:18 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.bsodmike.com/?p=684</guid>
		<description><![CDATA[Was rather interesting to find out that &#8216;Monday&#8217; is hardcoded into Rails as the start of the week, so working around this involved creating a custom initialiser that reopened two classes as follows: &#8230;and here&#8217;s the proof 12345678pry&#40;main&#41;&#62; Time.now.traditional_beginning_of_week =&#62; 2011-10-16 00:00:00 +0300 pry&#40;main&#41;&#62; Time.now.traditional_end_of_week =&#62; 2011-10-22 23:59:59 +0300 pry&#40;main&#41;&#62; Time.now.traditional_beginning_of_week.strftime&#40;'%e %A, %B %Y'&#41; =&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Was rather interesting to find out that &#8216;Monday&#8217; is hardcoded into Rails as the start of the week, so working around this involved creating a custom initialiser that reopened two classes as follows:</p>

<script src="https://gist.github.com/1304980.js?file=middle_east_week.rb"></script>

<p>&#8230;and here&#8217;s the proof</p>

<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">pry<span style="color:#006600; font-weight:bold;">&#40;</span>main<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>.<span style="color:#9900CC;">traditional_beginning_of_week</span><br />
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">2011</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">10</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">16</span> 00:00:00 <span style="color:#006600; font-weight:bold;">+</span>0300<br />
pry<span style="color:#006600; font-weight:bold;">&#40;</span>main<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>.<span style="color:#9900CC;">traditional_end_of_week</span><br />
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">2011</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">10</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">22</span> <span style="color:#006666;">23</span>:<span style="color:#006666;">59</span>:<span style="color:#006666;">59</span> <span style="color:#006600; font-weight:bold;">+</span>0300<br />
pry<span style="color:#006600; font-weight:bold;">&#40;</span>main<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>.<span style="color:#9900CC;">traditional_beginning_of_week</span>.<span style="color:#9900CC;">strftime</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'%e %A, %B %Y'</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;16 Sunday, October 2011&quot;</span><br />
pry<span style="color:#006600; font-weight:bold;">&#40;</span>main<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>.<span style="color:#9900CC;">traditional_end_of_week</span>.<span style="color:#9900CC;">strftime</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'%e %A, %B %Y'</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;22 Saturday, October 2011&quot;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://www.bsodmike.com/2011/10/22/rails-3-1-starting-the-week-on-sunday-as-in-the-middle-east/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>URI Obfuscation in Rails</title>
		<link>http://www.bsodmike.com/2011/10/21/uri-obfuscation-in-rails/</link>
		<comments>http://www.bsodmike.com/2011/10/21/uri-obfuscation-in-rails/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 20:06:43 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.bsodmike.com/?p=680</guid>
		<description><![CDATA[Was toying with my local yarddoc server and was perusing Paperclip&#8217;s rdoc and happend across an interesting note on URI obfuscation. John has indeed taken a very interesting approach and I&#8217;m looking forward to applying this to my custom S3 to API tool.]]></description>
			<content:encoded><![CDATA[<p>Was toying with my local yarddoc server and was perusing Paperclip&#8217;s rdoc and happend across an <a href="https://github.com/thoughtbot/paperclip/pull/416">interesting note on URI obfuscation</a>.  John has indeed taken a very interesting approach and I&#8217;m looking forward to applying this to my custom S3 to API tool.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bsodmike.com/2011/10/21/uri-obfuscation-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails 3.1: Plupload POST to Controller Causes Devise Session Logout (CSRF Protection Bypass)</title>
		<link>http://www.bsodmike.com/2011/10/19/rails-3-1-plupload-post-to-controller-causes-devise-session-logout-csrf-protection-bypass/</link>
		<comments>http://www.bsodmike.com/2011/10/19/rails-3-1-plupload-post-to-controller-causes-devise-session-logout-csrf-protection-bypass/#comments</comments>
		<pubDate>Wed, 19 Oct 2011 18:16:41 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.bsodmike.com/?p=677</guid>
		<description><![CDATA[Another interesting morning thanks to CSRF protecting kicking in when an upload with Plupload would POST to a controller&#8217;s action and subsequent reloads or visits to any parts caused Devise to log me out. This StackOverflow discussion and a blast from the past hinted in the right direction as for the issue. Thanks to Rene [...]]]></description>
			<content:encoded><![CDATA[<p>Another interesting morning thanks to CSRF protecting kicking in when an upload with Plupload would POST to a controller&#8217;s action and subsequent reloads or visits to any parts caused Devise to log me out.</p>

<p>This <a href="http://stackoverflow.com/questions/5049672/devise-session-immediately-expiring-on-js-call-ajax">StackOverflow discussion</a> and a <a href="http://weblog.rubyonrails.org/2011/2/8/csrf-protection-bypass-in-ruby-on-rails">blast from the past</a> hinted in the right direction as for the issue.</p>

<p>Thanks to Rene (<a href="https://github.com/rvanlieshout">rvanlieshout</a>) though the solution was far simpler.  Rather than passing the <strong>csrf_token</strong> via the HTTP header, I passed it in the POST params hash by leveraging Plupload&#8217;s <strong>multipart_params</strong> option</p>

<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">multipart_params<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>authenticity_token<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>

<p>and passed via the BeforeUpload event where &#8216;up&#8217; is the Uploader instance</p>

<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">up.<span style="color: #660066;">settings</span>.<span style="color: #660066;">multipart_params</span>.<span style="color: #660066;">authenticity_token</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;%=j @token.to_s &nbsp;%&gt;'</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://www.bsodmike.com/2011/10/19/rails-3-1-plupload-post-to-controller-causes-devise-session-logout-csrf-protection-bypass/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails 3.1: Bypassing Same-Origin Policy by Proxying JSON Request via Apache2 (mod_proxy)</title>
		<link>http://www.bsodmike.com/2011/10/19/rails-3-1-bypassing-same-origin-policy-by-proxying-json-request-via-apache2-mod_proxy/</link>
		<comments>http://www.bsodmike.com/2011/10/19/rails-3-1-bypassing-same-origin-policy-by-proxying-json-request-via-apache2-mod_proxy/#comments</comments>
		<pubDate>Wed, 19 Oct 2011 17:52:05 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Linux and Mac]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.bsodmike.com/?p=670</guid>
		<description><![CDATA[Few days ago I started looking at tackling the challenge of finding a viable solution to large online uploads and integrating them into an existing Rails powered site. Since a 5 GB limit on each video was acceptable, I decided to leverage Amazon S3 as the storage solution and the route I ended up taking [...]]]></description>
			<content:encoded><![CDATA[<p>Few days ago I started looking at tackling the challenge of finding a viable solution to large online uploads and integrating them into an existing Rails powered site. Since a 5 GB limit on each video was acceptable, I decided to leverage Amazon S3 as the storage solution and the route I ended up taking has resulted in creating a Rails app that essentially handles the upload to S3 and provides an API to those uploaded assets.</p>

<p>I liked the idea of using an HTML5 based upload mechanism, especially due to the clean approach taken in this article by AAAA.</p>

<p>However, once I had completed all the cool parts of getting the API to work, I dropped Devise in authenticate admin login &mdash; as well as leverage its :token_authenticatable module in the future for authenticated API access.  For the sake of this article, the host app was hosted at <strong>www.bar.org</strong>, and the uploader app at <strong>foo.bar.org</strong>.  The <a href="https://developer.mozilla.org/en/Same_origin_policy_for_JavaScript">Same-Origin Policy for Javascript</a> dictates failure for such access.  Trying to connect raised</p>

<blockquote>XMLHttpRequest cannot load http://foo.bar.org/api/v1/videos.json. Origin null is not allowed by Access-Control-Allow-Origin.</blockquote>

<p>You can read more about the <a href="http://stackoverflow.com/questions/3595515/xmlhttprequest-error-origin-null-is-not-allowed-by-access-control-allow-origin">specifics on StackOverflow</a> &mdash; my options were therefore limited to JSONP or proxying my JSON request through Apache itself!  Rather than having to deal with a lot more JS, I decided to take the far more straightforward approach by proxying the request via <strong>/videos</strong> and all this required was and update to the virtual host config by adding</p>

<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ProxyRequests Off<br />
<br />
<span style="color: #000000; font-weight: bold;">&lt;</span>Proxy <span style="color: #000000; font-weight: bold;">*&gt;</span><br />
Order Allow,Deny<br />
Allow from all<br />
<span style="color: #000000; font-weight: bold;">&lt;/</span>Proxy<span style="color: #000000; font-weight: bold;">&gt;</span><br />
<br />
ProxyPass <span style="color: #000000; font-weight: bold;">/</span>videos http:<span style="color: #000000; font-weight: bold;">//</span>foo.bar.org<span style="color: #000000; font-weight: bold;">/</span>api<span style="color: #000000; font-weight: bold;">/</span>v1<span style="color: #000000; font-weight: bold;">/</span>videos.json</div></td></tr></tbody></table></div>

<p>Huge <strong>Thanks</strong> to David Workman (workmad3) and Josh Rendek (namidark) for being orsum and their superb advice!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bsodmike.com/2011/10/19/rails-3-1-bypassing-same-origin-policy-by-proxying-json-request-via-apache2-mod_proxy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pushing to Multiple Git Repositories Simultaneously</title>
		<link>http://www.bsodmike.com/2011/10/17/pushing-to-multiple-git-repositories-simultaneously/</link>
		<comments>http://www.bsodmike.com/2011/10/17/pushing-to-multiple-git-repositories-simultaneously/#comments</comments>
		<pubDate>Sun, 16 Oct 2011 21:20:10 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Linux and Mac]]></category>
		<category><![CDATA[Git]]></category>

		<guid isPermaLink="false">http://www.bsodmike.com/?p=671</guid>
		<description><![CDATA[Setup your .git/config file with the following entry, and add as many repeating url entries for all the repos that will be updated simultaneously: 1234&#91;remote &#34;all&#34;&#93; &#160; # http://jeetworks.org/node/22 &#160; url = git@github.com:core_app &#160; url = git@bitbucket.org:bsodmike/core_app.git 1git push all --dry-run -v You want to be careful if attempting git push all &#8211;all &#8211;dry-run -v [...]]]></description>
			<content:encoded><![CDATA[<p>Setup your <strong>.git/config</strong> file with the following entry, and add as many repeating url entries for <a href="http://jeetworks.org/node/22">all the repos that will be updated simultaneously</a>:</p>

<div class="codecolorer-container yaml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="yaml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span class="br0">&#91;</span>remote &quot;all&quot;<span class="br0">&#93;</span><br />
&nbsp; # http://jeetworks.org/node/<span style="">22</span><br />
&nbsp; url = git@github.com:core_app<br />
&nbsp; url = git@bitbucket.org:bsodmike/core_app.git</div></td></tr></tbody></table></div>

<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">git</span> push all <span style="color: #660033;">--dry-run</span> <span style="color: #660033;">-v</span></div></td></tr></tbody></table></div>

<p>You want to be careful if attempting <strong>git push all &#8211;all &#8211;dry-run -v</strong> as this will create new branches for all local branches not present in your remotes.  Thankfully I ran a dry-run so although it seemed like I had gone and spawned a tone of branches, it was <em>just</em> a dry-run.</p>

<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">git</span> push all <span style="color: #660033;">--all</span> <span style="color: #660033;">--dry-run</span> <span style="color: #660033;">-v</span><br />
Pushing to <span style="color: #c20cb9; font-weight: bold;">git</span><span style="color: #000000; font-weight: bold;">@</span>github.com:core_app<br />
To <span style="color: #c20cb9; font-weight: bold;">git</span><span style="color: #000000; font-weight: bold;">@</span>github.com:core_app<br />
&nbsp;<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>new branch<span style="color: #7a0874; font-weight: bold;">&#93;</span> &nbsp; &nbsp; &nbsp;datetime_massage_exp -<span style="color: #000000; font-weight: bold;">&gt;</span> datetime_massage_exp<br />
&nbsp;<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>new branch<span style="color: #7a0874; font-weight: bold;">&#93;</span> &nbsp; &nbsp; &nbsp;jquery_attempt -<span style="color: #000000; font-weight: bold;">&gt;</span> jquery_attempt<br />
Pushing to <span style="color: #c20cb9; font-weight: bold;">git</span><span style="color: #000000; font-weight: bold;">@</span>bitbucket.org:bsodmike<span style="color: #000000; font-weight: bold;">/</span>core_app.git<br />
To <span style="color: #c20cb9; font-weight: bold;">git</span><span style="color: #000000; font-weight: bold;">@</span>bitbucket.org:bsodmike<span style="color: #000000; font-weight: bold;">/</span>core_app.git<br />
&nbsp;<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>new branch<span style="color: #7a0874; font-weight: bold;">&#93;</span> &nbsp; &nbsp; &nbsp;datetime_massage_exp -<span style="color: #000000; font-weight: bold;">&gt;</span> datetime_massage_exp<br />
&nbsp;<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>new branch<span style="color: #7a0874; font-weight: bold;">&#93;</span> &nbsp; &nbsp; &nbsp;development -<span style="color: #000000; font-weight: bold;">&gt;</span> development<br />
&nbsp;<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>new branch<span style="color: #7a0874; font-weight: bold;">&#93;</span> &nbsp; &nbsp; &nbsp;jquery_attempt -<span style="color: #000000; font-weight: bold;">&gt;</span> jquery_attempt</div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://www.bsodmike.com/2011/10/17/pushing-to-multiple-git-repositories-simultaneously/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails: Create a User Profile on Registration with Devise</title>
		<link>http://www.bsodmike.com/2011/09/30/rails-create-a-user-profile-on-registration-with-devise/</link>
		<comments>http://www.bsodmike.com/2011/09/30/rails-create-a-user-profile-on-registration-with-devise/#comments</comments>
		<pubDate>Fri, 30 Sep 2011 12:10:01 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.bsodmike.com/?p=666</guid>
		<description><![CDATA[The trick to the above was just discussed on StackOverflow. You will have to of course override the default registration controller and flesh your own and setup the new action as follows 1234567891011121314151617181920= simple_form_for&#40;resource, :as =&#62; resource_name, :url =&#62; registration_path&#40;resource_name&#41;&#41; do &#124;f&#124; &#160; &#160; = devise_error_messages! &#160; &#160; = f.input :username, &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>The trick to the above was<a href="http://stackoverflow.com/questions/7608532/create-a-user-profile-upon-registration-add-profile-form-fields-to-devise-registr/7608622"> just discussed on StackOverflow</a>.  You will have to of course override the default registration controller and flesh your own and setup the <strong>new</strong> action as follows</p>

<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">= simple_form_for<span style="color:#006600; font-weight:bold;">&#40;</span>resource, <span style="color:#ff3333; font-weight:bold;">:as</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> resource_name, <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> registration_path<span style="color:#006600; font-weight:bold;">&#40;</span>resource_name<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span><br />
<br />
&nbsp; &nbsp; = devise_error_messages!<br />
<br />
&nbsp; &nbsp; = f.<span style="color:#9900CC;">input</span> <span style="color:#ff3333; font-weight:bold;">:username</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:label</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Username'</span><br />
&nbsp; &nbsp; = f.<span style="color:#9900CC;">input</span> <span style="color:#ff3333; font-weight:bold;">:email</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:label</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Email'</span><br />
&nbsp; &nbsp; = f.<span style="color:#9900CC;">input</span> <span style="color:#ff3333; font-weight:bold;">:password</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:label</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Password'</span><br />
&nbsp; &nbsp; = f.<span style="color:#9900CC;">input</span> <span style="color:#ff3333; font-weight:bold;">:password_confirmation</span>, &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:label</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Password confirm'</span><br />
<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">//</span> make a new profile <span style="color:#9966CC; font-weight:bold;">in</span> memory<br />
&nbsp; &nbsp; = resource.<span style="color:#9900CC;">build_profile</span><br />
<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">//</span> start fields <span style="color:#9966CC; font-weight:bold;">for</span> profile<br />
&nbsp; &nbsp; = f.<span style="color:#9900CC;">fields_for</span> <span style="color:#ff3333; font-weight:bold;">:profile</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; &nbsp; = f.<span style="color:#9900CC;">label</span> <span style="color:#ff3333; font-weight:bold;">:bod_day</span><br />
&nbsp; &nbsp; &nbsp; = f.<span style="color:#9900CC;">text_field</span> <span style="color:#ff3333; font-weight:bold;">:bod_day</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">//</span> <span style="color:#9966CC; font-weight:bold;">end</span> fields <span style="color:#9966CC; font-weight:bold;">for</span> profile<br />
<br />
<br />
&nbsp; &nbsp; = f.<span style="color:#9900CC;">button</span> <span style="color:#ff3333; font-weight:bold;">:submit</span>, t<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:submit</span>, <span style="color:#ff3333; font-weight:bold;">:scope</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:register</span><span style="color:#006600; font-weight:bold;">&#41;</span></div></td></tr></tbody></table></div>

<p>As with <strong>accepts_nested_attributes_for :profile</strong> in the <strong>User</strong> model, one would also include <strong>attr_accessible &#8230;, :profile_attributes</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bsodmike.com/2011/09/30/rails-create-a-user-profile-on-registration-with-devise/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails to_json or as_json?</title>
		<link>http://www.bsodmike.com/2011/09/30/rails-to_json-or-as_json/</link>
		<comments>http://www.bsodmike.com/2011/09/30/rails-to_json-or-as_json/#comments</comments>
		<pubDate>Thu, 29 Sep 2011 18:51:07 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.bsodmike.com/?p=663</guid>
		<description><![CDATA[Thanks to Jonathan Julian&#8217;s fantastic post on the subject, here&#8217;s some code that I used today in a project. I set about defining an instance method as_json in the model I was interested in, in this case Employee 123&#160; def as_json&#40;options=&#123;&#125;&#41; &#160; &#160; &#123; :id =&#62; self.id, :name =&#62; self.name, :title =&#62; self.title, :email =&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Thanks to <a href="http://jonathanjulian.com/2010/04/rails-to_json-or-as_json/">Jonathan Julian&#8217;s fantastic post</a> on the subject, here&#8217;s some code that I used today in a project.  I set about defining an instance method <strong>as_json</strong> in the model I was interested in, in this case <strong>Employee</strong></p>

<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> as_json<span style="color:#006600; font-weight:bold;">&#40;</span>options=<span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">id</span>, <span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">name</span>, <span style="color:#ff3333; font-weight:bold;">:title</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">title</span>, <span style="color:#ff3333; font-weight:bold;">:email</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">email</span>, <span style="color:#ff3333; font-weight:bold;">:phone</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">phone</span>, <span style="color:#ff3333; font-weight:bold;">:image</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">image</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>

<p>and in the controller</p>

<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> EmployeesController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> index<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@employees</span> = Employee.<span style="color:#9900CC;">all</span><br />
&nbsp; &nbsp; respond_to <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>format<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">json</span> &nbsp;<span style="color:#006600; font-weight:bold;">&#123;</span> render <span style="color:#ff3333; font-weight:bold;">:json</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@employees</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>

<p>Visiting &#8216;/employees.json&#8217; yields the expected JSON</p>

<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #ff0000;">&quot;id&quot;</span>:<span style="color: #000000;">1</span>,<span style="color: #ff0000;">&quot;name&quot;</span>:<span style="color: #ff0000;">&quot;John Doe&quot;</span>,<span style="color: #ff0000;">&quot;title&quot;</span>:<span style="color: #ff0000;">&quot;Prof.&quot;</span>,<span style="color: #ff0000;">&quot;email&quot;</span>:<span style="color: #ff0000;">&quot;john@foo.com&quot;</span>,<span style="color: #ff0000;">&quot;phone&quot;</span>:<span style="color: #ff0000;">&quot;21343245252343&quot;</span>,<span style="color: #ff0000;">&quot;image&quot;</span>:<span style="color: #ff0000;">&quot;john.jpg&quot;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span></div></td></tr></tbody></table></div>

<p><strong><em>Update</em></strong>:  You can also pass details from your controller to <strong>as_json</strong> as follows:</p>

<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">json</span> &nbsp;<span style="color:#006600; font-weight:bold;">&#123;</span> render <span style="color:#ff3333; font-weight:bold;">:json</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@employees</span>.<span style="color:#9900CC;">as_json</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:fax</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;23423545&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span></div></td></tr></tbody></table></div>

<p>You can then access this in the <strong>as_json</strong> method via <strong>options[:fax]</strong> and update the JSON object tree response as you wish.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bsodmike.com/2011/09/30/rails-to_json-or-as_json/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Guard causing REPLs to lag&#8230; and stop working?</title>
		<link>http://www.bsodmike.com/2011/09/29/guard-causing-repls-to-lag-and-stop-working/</link>
		<comments>http://www.bsodmike.com/2011/09/29/guard-causing-repls-to-lag-and-stop-working/#comments</comments>
		<pubDate>Thu, 29 Sep 2011 13:17:18 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.bsodmike.com/?p=657</guid>
		<description><![CDATA[Becky was kind enough to send me a link to the patch on Github, the solution simply requiring an update to version 0.8.0 of Guard by adding the following your Gemfile 1gem 'guard', :git =&#62; 'git://github.com/guard/guard.git' This will ensure the rails console and pry to continue working with Guard&#8230;]]></description>
			<content:encoded><![CDATA[<p>Becky was kind enough to send me a <a href="https://github.com/guard/guard/issues/143">link to the patch on Github</a>, the solution simply requiring an update to version 0.8.0 of Guard by adding the following your <strong>Gemfile</strong></p>

<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">gem <span style="color:#996600;">'guard'</span>, <span style="color:#ff3333; font-weight:bold;">:git</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'git://github.com/guard/guard.git'</span></div></td></tr></tbody></table></div>

<p>This will ensure the rails console and <strong>pry</strong> to continue working with Guard&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bsodmike.com/2011/09/29/guard-causing-repls-to-lag-and-stop-working/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HOWTO: Rails 3.1 Engines with RSpec</title>
		<link>http://www.bsodmike.com/2011/09/22/howto-rails-3-1-engines-with-rspec/</link>
		<comments>http://www.bsodmike.com/2011/09/22/howto-rails-3-1-engines-with-rspec/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 21:37:44 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.bsodmike.com/?p=650</guid>
		<description><![CDATA[You&#8217;ll need RVM and at least Ruby 1.9.2-p290 installed to proceed. Run the following to generate the engine 1rails plugin new epic_fail --skip-test-unit --full --mountable --dummy-path=spec/dummy Add the following .rvmrc file to your engine&#8217;s root folder 1rvm use 1.9.2@rails31 --create --rvmrc This will automatically generate the files and folder structure of your engine. At the [...]]]></description>
			<content:encoded><![CDATA[<p>You&#8217;ll need RVM and at least Ruby 1.9.2-p290 installed to proceed.  Run the following to generate the engine</p>

<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">rails plugin new epic_fail <span style="color: #660033;">--skip-test-unit</span> <span style="color: #660033;">--full</span> <span style="color: #660033;">--mountable</span> <span style="color: #660033;">--dummy-path</span>=spec<span style="color: #000000; font-weight: bold;">/</span>dummy</div></td></tr></tbody></table></div>

<p>Add the following <strong>.rvmrc</strong> file to your engine&#8217;s root folder</p>

<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">rvm use 1.9.2<span style="color: #000000; font-weight: bold;">@</span>rails31 <span style="color: #660033;">--create</span> <span style="color: #660033;">--rvmrc</span></div></td></tr></tbody></table></div>

<p>This will automatically generate the files and folder structure of your engine.  At the time of writing my gemspec looked like</p>

<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$:.<span style="color:#9900CC;">push</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;../lib&quot;</span>, <span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># Maintain your gem's version:</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;epic_fail/version&quot;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># Describe your gem and declare its dependencies:</span><br />
<span style="color:#6666ff; font-weight:bold;">Gem::Specification</span>.<span style="color:#9900CC;">new</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>s<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; s.<span style="color:#9900CC;">name</span> &nbsp; &nbsp; &nbsp; &nbsp;= <span style="color:#996600;">&quot;epic_fail&quot;</span><br />
&nbsp; s.<span style="color:#9900CC;">version</span> &nbsp; &nbsp; = <span style="color:#6666ff; font-weight:bold;">EpicFail::VERSION</span><br />
&nbsp; s.<span style="color:#9900CC;">authors</span> &nbsp; &nbsp; = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;TODO: Your name&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; s.<span style="color:#9900CC;">email</span> &nbsp; &nbsp; &nbsp; = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;TODO: Your email&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; s.<span style="color:#9900CC;">homepage</span> &nbsp; &nbsp;= <span style="color:#996600;">&quot;TODO&quot;</span><br />
&nbsp; s.<span style="color:#9900CC;">summary</span> &nbsp; &nbsp; = <span style="color:#996600;">&quot;TODO: Summary of EpicFail.&quot;</span><br />
&nbsp; s.<span style="color:#9900CC;">description</span> = <span style="color:#996600;">&quot;TODO: Description of EpicFail.&quot;</span><br />
<br />
&nbsp; s.<span style="color:#9900CC;">files</span> = <span style="color:#CC00FF; font-weight:bold;">Dir</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;{app,config,db,lib}/**/*&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;MIT-LICENSE&quot;</span>, <span style="color:#996600;">&quot;Rakefile&quot;</span>, <span style="color:#996600;">&quot;README.rdoc&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
<br />
&nbsp; s.<span style="color:#9900CC;">add_dependency</span> <span style="color:#996600;">&quot;rails&quot;</span>, <span style="color:#996600;">&quot;~&gt; 3.1.0&quot;</span><br />
&nbsp; s.<span style="color:#9900CC;">add_dependency</span> <span style="color:#996600;">&quot;jquery-rails&quot;</span><br />
<br />
&nbsp; s.<span style="color:#9900CC;">add_development_dependency</span> <span style="color:#996600;">&quot;sqlite3&quot;</span><br />
&nbsp; s.<span style="color:#9900CC;">add_development_dependency</span> <span style="color:#996600;">&quot;thin&quot;</span><br />
&nbsp; s.<span style="color:#9900CC;">add_development_dependency</span> <span style="color:#996600;">&quot;rspec-rails&quot;</span><br />
&nbsp; s.<span style="color:#9900CC;">add_development_dependency</span> <span style="color:#996600;">&quot;capybara&quot;</span><br />
&nbsp; s.<span style="color:#9900CC;">add_development_dependency</span> <span style="color:#996600;">&quot;factory_girl_rails&quot;</span><br />
&nbsp; s.<span style="color:#9900CC;">add_development_dependency</span> <span style="color:#996600;">&quot;guard-rspec&quot;</span><br />
&nbsp; s.<span style="color:#9900CC;">add_development_dependency</span> <span style="color:#996600;">&quot;rb-fsevent&quot;</span><br />
&nbsp; s.<span style="color:#9900CC;">add_development_dependency</span> <span style="color:#996600;">&quot;yard&quot;</span><br />
&nbsp; s.<span style="color:#9900CC;">add_development_dependency</span> <span style="color:#996600;">&quot;pry&quot;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>

<p>The development dependencies comprises of my preferred testing stack for TDD with RSpec and BDD with RSpec and Capybara.  Guard to keep a watch on the various files that may be updated (rb-fsevent is for Mac only), Factory Girl for factories, and my REPL replacement &mdash; pry.</p>

<p>At this stage you will want to perform</p>

<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">rails g rspec:<span style="color: #c20cb9; font-weight: bold;">install</span><br />
guard init rspec</div></td></tr></tbody></table></div>

<p>Set about updating your <strong>spec_helper.rb</strong></p>

<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#008000; font-style:italic;"># This file is copied to spec/ when you run 'rails generate rspec:install'</span><br />
ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;RAILS_ENV&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#996600;">'test'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;../dummy/config/environment&quot;</span>, <span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rspec/rails'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'capybara/rspec'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'pry'</span><br />
<br />
ENGINE_RAILS_ROOT = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#996600;">'../'</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#008000; font-style:italic;"># Requires supporting ruby files with custom matchers and macros, etc,</span><br />
<span style="color:#008000; font-style:italic;"># in spec/support/ and its subdirectories.</span><br />
<span style="color:#CC00FF; font-weight:bold;">Dir</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>ENGINE_RAILS_ROOT, <span style="color:#996600;">&quot;spec/support/**/*.rb&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC0066; font-weight:bold;">require</span> f <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<br />
RSpec.<span style="color:#9900CC;">configure</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>config<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; <span style="color:#008000; font-style:italic;"># == Mock Framework</span><br />
&nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; <span style="color:#008000; font-style:italic;"># If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:</span><br />
&nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; <span style="color:#008000; font-style:italic;"># config.mock_with :mocha</span><br />
&nbsp; <span style="color:#008000; font-style:italic;"># config.mock_with :flexmock</span><br />
&nbsp; <span style="color:#008000; font-style:italic;"># config.mock_with :rr</span><br />
&nbsp; config.<span style="color:#9900CC;">mock_with</span> <span style="color:#ff3333; font-weight:bold;">:rspec</span><br />
<br />
&nbsp; <span style="color:#008000; font-style:italic;"># Remove this line if you're not using ActiveRecord or ActiveRecord fixtures</span><br />
&nbsp; <span style="color:#008000; font-style:italic;">#config.fixture_path = &quot;#{::Rails.root}/spec/fixtures&quot;</span><br />
<br />
&nbsp; <span style="color:#008000; font-style:italic;"># If you're not using ActiveRecord, or you'd prefer not to run each of your</span><br />
&nbsp; <span style="color:#008000; font-style:italic;"># examples within a transaction, remove the following line or assign false</span><br />
&nbsp; <span style="color:#008000; font-style:italic;"># instead of true.</span><br />
&nbsp; config.<span style="color:#9900CC;">use_transactional_fixtures</span> = <span style="color:#0000FF; font-weight:bold;">true</span><br />
&nbsp; <br />
&nbsp; config.<span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">Capybara::DSL</span>, <span style="color:#ff3333; font-weight:bold;">:example_group</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:file_path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">/</span>\bspec\<span style="color:#006600; font-weight:bold;">/</span>requests\<span style="color:#006600; font-weight:bold;">//</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; config.<span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">EpicFail::Engine</span>.<span style="color:#9900CC;">routes</span>.<span style="color:#9900CC;">url_helpers</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>

<p>and added to the engine&#8217;s <strong>Rakefile</strong></p>

<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rake'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rspec/core'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rspec/core/rake_task'</span><br />
<br />
<span style="color:#6666ff; font-weight:bold;">RSpec::Core::RakeTask</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:spec</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>spec<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; spec.<span style="color:#9900CC;">pattern</span> = FileList<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'spec/**/*_spec.rb'</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
desc <span style="color:#996600;">'Default: Run all specs.'</span><br />
task <span style="color:#ff3333; font-weight:bold;">:default</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:spec</span></div></td></tr></tbody></table></div>

<p>I&#8217;ve made some very specific tweaks to the above with regards to testing &#8211; these have been gleaned from the included references.  I also wanted to decouple the gemspec of the dummy/app from the engine itself and to do this made some changes in <strong>boot.rb</strong></p>

<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span><br />
<span style="color:#008000; font-style:italic;"># gemfile = File.expand_path('../../../../Gemfile', __FILE__)</span><br />
<span style="color:#008000; font-style:italic;"># </span><br />
<span style="color:#008000; font-style:italic;"># if File.exist?(gemfile)</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; ENV['BUNDLE_GEMFILE'] = gemfile</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; require 'bundler'</span><br />
<span style="color:#008000; font-style:italic;"># &nbsp; Bundler.setup</span><br />
<span style="color:#008000; font-style:italic;"># end</span><br />
<br />
<span style="color:#008000; font-style:italic;"># Set up gems listed in the Gemfile.</span><br />
ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'BUNDLE_GEMFILE'</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'../../Gemfile'</span>, <span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'bundler/setup'</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'BUNDLE_GEMFILE'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
$:.<span style="color:#9900CC;">unshift</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'../../../../lib'</span>, <span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span></div></td></tr></tbody></table></div>

<p>and the added Gemfile in spec/dummy</p>

<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">source <span style="color:#996600;">&quot;http://rubygems.org&quot;</span><br />
<br />
gem <span style="color:#996600;">&quot;rails&quot;</span>, <span style="color:#996600;">&quot;~&gt; 3.1.0&quot;</span><br />
gem <span style="color:#996600;">&quot;epic_fail&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'../../../epic_fail'</span><br />
gem <span style="color:#996600;">&quot;jquery-rails&quot;</span><br />
<br />
group <span style="color:#ff3333; font-weight:bold;">:development</span>, <span style="color:#ff3333; font-weight:bold;">:test</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; gem <span style="color:#996600;">&quot;sqlite3&quot;</span><br />
&nbsp; gem <span style="color:#996600;">&quot;thin&quot;</span><br />
&nbsp; gem <span style="color:#996600;">&quot;rspec-rails&quot;</span><br />
&nbsp; gem <span style="color:#996600;">&quot;capybara&quot;</span><br />
&nbsp; gem <span style="color:#996600;">&quot;factory_girl_rails&quot;</span><br />
&nbsp; gem <span style="color:#996600;">&quot;guard-rspec&quot;</span><br />
&nbsp; gem <span style="color:#996600;">&quot;rb-fsevent&quot;</span><br />
&nbsp; gem <span style="color:#996600;">&quot;yard&quot;</span><br />
&nbsp; gem <span style="color:#996600;">&quot;pry&quot;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>

<p>Notice how the engine it referenced via relative paths.  There were several tweaks made to the Railtie itself and how <a href="https://gist.github.com/1228809">routes were dynamically generated</a> in the dummy/app.</p>

<h2>Github Source: <a href="https://github.com/bsodmike/EpicFail">https://github.com/bsodmike/EpicFail</a></h2>

<p>Review the commits made to <a href="https://github.com/bsodmike/EpicFail">my first engine, EpicFail</a> &mdash; fork it if you like as well!</p>

<p>As per the latest commit, I&#8217;ve deployed some middleware to handle exception notification &#8211; as a simple test.  It also includes <a href="https://gist.github.com/1231537">modification to print Rails bootstrap initializer points</a> whenever the environment is loaded.</p>

<p>One good thing that came out of this little adventure was the discovery of a l<a href="https://github.com/rails/rails/pull/3091">ittle bug in the plugin_new generator</a> &#8211; my approach was to incorporate the fix within the engine, however, Pastorino has applied the fix to the dummy/app&#8217;s Gemfile itself.</p>

<p>It&#8217;s certainly been a thrilling 48 hours and I&#8217;m completely enjoying my pursuits with Rails Engines thus far.</p>

<h2>References</h2>

<ul>
    <li><a href="http://rubyx.com/2011/03/01/start-your-engines">Start your engines! by Ryan Bigg</a></li>
    <li><a href="http://www.stubbleblog.com/index.php/2011/04/writing-rails-engines-getting-started/">Writing Rails Engines #1: Getting Started</a></li>

    <li><a href="http://www.themodestrubyist.com/2010/03/01/rails-3-plugins---part-1---the-big-picture/">Rails 3 Plugins &#8211; Part 1 &#8211; The Big Picture</a></li>
    <li><a href="http://www.themodestrubyist.com/2010/03/05/rails-3-plugins---part-2---writing-an-engine/">Rails 3 Plugins &#8211; Part 2 &#8211; Writing an Engine</a></li>
    <li><a href="http://www.themodestrubyist.com/2010/03/16/rails-3-plugins---part-3---rake-tasks-generators-initializers-oh-my/">Rails 3 Plugins &#8211; Part 3 &#8211; Rake Tasks, Generators, Initializers, Oh-My!</a></li>
    <li><a href="http://api.rubyonrails.org/classes/Rails/Engine.html">Rails::Engine < Rails::Railtie</a></li>
    <li><a href="https://gist.github.com/ec02bd1581c941ab31e4#file_2_engine.rdoc">Gist by Jose Valim covering engines</a>, Railties, plugins and other concepts.</li>
    <li><a href="http://stackoverflow.com/questions/7452037/testing-rails-3-1-mountable-engine-with-rspec">http://stackoverflow.com/questions/7452037/testing-rails-3-1-mountable-engine-with-rspec</a></li>
    <li><a href="http://www.r3ef.com/Articles/2010/10/11/gem-testing-with-rspec.html">http://www.r3ef.com/Articles/2010/10/11/gem-testing-with-rspec.html</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.bsodmike.com/2011/09/22/howto-rails-3-1-engines-with-rspec/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
