<?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>Tatva-Artha &#187; All</title>
	<atom:link href="http://www.tatvartha.com/category/all/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tatvartha.com</link>
	<description>meaning of &#34;it&#34;</description>
	<lastBuildDate>Sat, 22 Oct 2011 22:00:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Upgrading to ruby 1.9: rbx-require-relative requires Ruby version ~&gt; 1.8.7</title>
		<link>http://www.tatvartha.com/2011/08/upgrading-to-ruby-1-9-rbx-require-relative-requires-ruby-version-1-8-7/</link>
		<comments>http://www.tatvartha.com/2011/08/upgrading-to-ruby-1-9-rbx-require-relative-requires-ruby-version-1-8-7/#comments</comments>
		<pubDate>Sun, 21 Aug 2011 18:55:49 +0000</pubDate>
		<dc:creator>Sharad</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[gemfile]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.tatvartha.com/?p=493</guid>
		<description><![CDATA[If you are upgrading from ruby 1.8 or Ruby Enterprise 1.8.7 to ruby 1.9.2, you may encounter this error. Installing rbx-require-relative (0.0.5) Unfortunately, a fatal error has occurred. Please report this error to the Bundler issue tracker at https://github.com/carlhuda/ bundler/issues so that we can fix it. Thanks!/Users/sjain/.rvm/rubies/ruby-1.9.2-p290/ lib/ruby/site_ruby/1.9.1/rubygems/ installer.rb:364:in `ensure_required_ruby_version_met': rbx-require-relative requires Ruby version ~> [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>If you are upgrading from ruby 1.8 or Ruby Enterprise 1.8.7 to ruby 1.9.2, you may encounter this error.</p>
<pre land="bash">
Installing rbx-require-relative (0.0.5) Unfortunately, a fatal error has occurred.
Please report this error to the Bundler issue tracker at https://github.com/carlhuda/
bundler/issues so that we can fix it. Thanks!/Users/sjain/.rvm/rubies/ruby-1.9.2-p290/
lib/ruby/site_ruby/1.9.1/rubygems/ installer.rb:364:in `ensure_required_ruby_version_met':
rbx-require-relative requires Ruby version ~> 1.8.7. (Gem::InstallError)
</pre>
<p>This most likely happens because you are declaring a dependency on ruby-debug gem in your Gemfile.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">group <span style="color:#ff3333; font-weight:bold;">:development</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  gem <span style="color:#996600;">'ruby-debug'</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>With ruby 1.9, you need to update this with new gem name ruby-debug19.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">group <span style="color:#ff3333; font-weight:bold;">:development</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  gem <span style="color:#996600;">'ruby-debug19'</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This will eliminate the dependency on rbx-require-relative and fix the issue.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.tatvartha.com/2011/08/upgrading-to-ruby-1-9-rbx-require-relative-requires-ruby-version-1-8-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Developing webapp that require you to expose your local machine on web</title>
		<link>http://www.tatvartha.com/2011/06/developing-webapp-that-require-you-to-expose-your-local-machine-on-web/</link>
		<comments>http://www.tatvartha.com/2011/06/developing-webapp-that-require-you-to-expose-your-local-machine-on-web/#comments</comments>
		<pubDate>Sat, 11 Jun 2011 01:54:35 +0000</pubDate>
		<dc:creator>Sharad</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[paypal]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[tunnel]]></category>

		<guid isPermaLink="false">http://www.tatvartha.com/?p=489</guid>
		<description><![CDATA[If you&#8217;ve ever developed facebook applications or have needed to integrate with paypal payment service, you know that those services require a reverse connection from their servers to your webapp to complete full circle. The process of making your webapp, running on your machine during development, to outside world was painful at best. Not anymore. [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve ever developed facebook applications or have needed to integrate with paypal payment service, you know that those services require a reverse connection from their servers to your webapp to complete full circle. The process of making your webapp, running on your machine during development, to outside world was painful at best.</p>
<p>Not anymore. With this service called &#8220;localtunnel&#8221;, it is a piece of cake.</p>
<p><a href="http://progrium.com/localtunnel/">http://progrium.com/localtunnel/</a></p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.tatvartha.com/2011/06/developing-webapp-that-require-you-to-expose-your-local-machine-on-web/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Setting environment variables in Max OSX</title>
		<link>http://www.tatvartha.com/2011/05/setting-environment-variables-in-max-osx/</link>
		<comments>http://www.tatvartha.com/2011/05/setting-environment-variables-in-max-osx/#comments</comments>
		<pubDate>Mon, 16 May 2011 15:12:25 +0000</pubDate>
		<dc:creator>Sharad</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[environment variable]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://www.tatvartha.com/?p=481</guid>
		<description><![CDATA[Any a developer switching from linux to mac, the way to set environment variables is similar yet different enough that is annoying at times. I have so far failed to find a good documentation on where and how to set those in mac osx. Today I found one here. My takeaway: Mac OS X applies [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Any a developer switching from linux to mac, the way to set environment variables is similar yet different enough that is annoying at times. I have so far failed to find a good documentation on where and how to set those in mac osx. Today I found one <a href="http://devnet.jetbrains.net/docs/DOC-1160">here</a>.</p>
<p><strong>My takeaway:</strong></p>
<p>Mac OS X applies .bash_profile and .profile only for Terminal.app environment and  Apple&#8217;s technical documentation suggests using ~/.MacOSX/environment.plist for other applications. So, by default  PATH value will differ for RubyMine and the console.</p>
<p>For managing the global environments, it also recommends a <a href="http://www.apple.com/downloads/macosx/system_disk_utilities/environmentvariablepreferencepane.html">system preference pane app</a>. This worked for me.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.tatvartha.com/2011/05/setting-environment-variables-in-max-osx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging Passenger Memory Issues</title>
		<link>http://www.tatvartha.com/2011/05/debugging-passenger-memory-issues/</link>
		<comments>http://www.tatvartha.com/2011/05/debugging-passenger-memory-issues/#comments</comments>
		<pubDate>Sun, 01 May 2011 18:05:09 +0000</pubDate>
		<dc:creator>Sharad</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[passenger]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.tatvartha.com/?p=479</guid>
		<description><![CDATA[There was an interesting thread on ruby-passenger application server newsgroup recently: http://groups.google.com/group/phusion-passenger/browse_thread/thread/f48ad0eb018a2482 Here is my take away: # returns [class, count] tuples for all active records in the heap def ar_space GC.start h = Hash.new&#40;0&#41; ObjectSpace.each_object do &#124;o&#124; next if o.__id__ == self.__id__ next unless ActiveRecord::Base === o h&#91;o.class.to_s&#93; += 1 end return h.sort&#123;&#124;a,b&#124; -&#40;a&#91;1&#93;&#60;=&#62;b&#91;1&#93;&#41;&#125; [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>There was an interesting thread on ruby-passenger application server newsgroup recently: <a href="http://groups.google.com/group/phusion-passenger/browse_thread/thread/f48ad0eb018a2482">http://groups.google.com/group/phusion-passenger/browse_thread/thread/f48ad0eb018a2482</a></p>
<p>Here is my take away:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#008000; font-style:italic;"># returns [class, count] tuples for all active records in the heap </span>
  <span style="color:#9966CC; font-weight:bold;">def</span> ar_space 
    <span style="color:#CC00FF; font-weight:bold;">GC</span>.<span style="color:#9900CC;">start</span> 
    h = <span style="color:#CC00FF; font-weight:bold;">Hash</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> 
    <span style="color:#CC00FF; font-weight:bold;">ObjectSpace</span>.<span style="color:#9900CC;">each_object</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>o<span style="color:#006600; font-weight:bold;">|</span> 
      <span style="color:#9966CC; font-weight:bold;">next</span> <span style="color:#9966CC; font-weight:bold;">if</span> o.__id__ == <span style="color:#0000FF; font-weight:bold;">self</span>.__id__ 
      <span style="color:#9966CC; font-weight:bold;">next</span> <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span> === o 
      h<span style="color:#006600; font-weight:bold;">&#91;</span>o.<span style="color:#9966CC; font-weight:bold;">class</span>.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#006666;">1</span> 
    <span style="color:#9966CC; font-weight:bold;">end</span> 
    <span style="color:#0000FF; font-weight:bold;">return</span> h.<span style="color:#9900CC;">sort</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>a,b<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">-</span><span style="color:#006600; font-weight:bold;">&#40;</span>a<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&lt;=&gt;</span>b<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span> 
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Nifty little snippet to fetch number of active record objects on heap. I am guessing, incorporating this as Controller after_filter can help with cost of each request..</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.tatvartha.com/2011/05/debugging-passenger-memory-issues/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deploy at will!</title>
		<link>http://www.tatvartha.com/2011/04/deploy-at-will/</link>
		<comments>http://www.tatvartha.com/2011/04/deploy-at-will/#comments</comments>
		<pubDate>Thu, 07 Apr 2011 02:03:08 +0000</pubDate>
		<dc:creator>Sharad</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[deploy]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.tatvartha.com/?p=474</guid>
		<description><![CDATA[Shamelessly copying one point from a github blog. It is that good. Deploy at Will! At the first RailsConf I had the pleasure of hearing Martin Fowler deliver an amazing keynote. He made some apt metaphors regarding agile development that I will now paraphrase and mangle. Imagine you’re tasked with building a computer controlled gun [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Shamelessly copying one point from a <a href="http://tom.preston-werner.com/2011/03/29/ten-lessons-from-githubs-first-year.html">github blog</a>. It is that good.</p>
<h3>Deploy at Will!</h3>
<p>At the first RailsConf I had the pleasure of hearing Martin Fowler deliver an amazing keynote. He made some apt metaphors regarding agile development that I will now paraphrase and mangle.</p>
<p>Imagine you’re tasked with building a computer controlled gun that can accurately hit a target about 50 meters distant. That is the only requirement. One way to do this is to build a complex machine that measures every possible variable (wind, elevation, temperature, etc.) before the shot and then takes aim and shoots. Another approach is to build a simple machine that fires rapidly and can detect where each shot hits. It then uses this information to adjust the aim of the next shot, quickly homing in on the target a little at a time.</p>
<p>The difference between these two approaches is to realize that bullets are cheap. By the time the former group has perfected their wind detection instrument, you’ll have finished your simple weapon and already hit the target.</p>
<p>In the world of web development, the target is your ideal offering, the bullets are your site deploys, and your customers provide the feedback mechanism. The first year of a web offering is a magical one. Your customers are most likely early adopters and love to see new features roll out every few weeks. If this results in a little bit of downtime, they’ll easily forgive you, as long as those features are sweet. In the early days of GitHub, we’d deploy up to ten times in one afternoon, always inching closer to that target.</p>
<p>Make good use of that first year, because once the big important customers start rolling in, you have to be a lot more careful about hitting one of them with a stray bullet. Later in the game, downtime and botched deploys are money lost and you have to rely more on building instruments to predict where you should aim.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.tatvartha.com/2011/04/deploy-at-will/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript Garden</title>
		<link>http://www.tatvartha.com/2011/03/javascript-garden/</link>
		<comments>http://www.tatvartha.com/2011/03/javascript-garden/#comments</comments>
		<pubDate>Sat, 19 Mar 2011 05:12:30 +0000</pubDate>
		<dc:creator>Sharad</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.tatvartha.com/?p=472</guid>
		<description><![CDATA[If you consider yourself a beginner or intermediate Javascript developer and feel the need to advance, here&#8217;s something that may be right up you ally: Javascript Garden. No related posts. Related posts brought to you by Yet Another Related Posts Plugin.


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>If you consider yourself a beginner or intermediate Javascript developer and feel the need to advance, here&#8217;s something that may be right up you ally: <a href="http://bonsaiden.github.com/JavaScript-Garden/">Javascript Garden</a>.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.tatvartha.com/2011/03/javascript-garden/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mocha unexpected invocation errors</title>
		<link>http://www.tatvartha.com/2011/03/mocha-unexpected-invocation-errors/</link>
		<comments>http://www.tatvartha.com/2011/03/mocha-unexpected-invocation-errors/#comments</comments>
		<pubDate>Sat, 12 Mar 2011 04:38:39 +0000</pubDate>
		<dc:creator>Sharad</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[mocha]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.tatvartha.com/?p=470</guid>
		<description><![CDATA[If you find that your tests pass when run alone but fail with &#8220;unexpected invocation&#8221; inside &#8220;rake test&#8221;, you are most likely seeing behavior that is caused by mocha load order. This is a documented gotcha with mocha. And also discussed here. It happens when mocha gem is listed as library dependency inside rails app. [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>If you find that your tests pass when run alone but fail with &#8220;unexpected invocation&#8221; inside &#8220;rake test&#8221;, you are most likely seeing behavior that is caused by mocha load order.</p>
<p>This is a <a href="http://mocha.rubyforge.org/">documented</a> gotcha with mocha. And also discussed <a href="http://blog.agoragames.com/2010/09/10/rails-3-mocha-load-order-gotcha/">here</a>.</p>
<p>It happens when mocha gem is listed as library dependency inside rails app. The library gets loaded too soon. The fix is to load mocha after rails has booted up.</p>
<p>For rails < 3.0.0, this means removing -- config.gem 'mocha' -- entry from config/environment.rb and adding -- require 'mocha' -- at the bottom of test/test_helper.rb.</p>
<p>For rails >= 3.0.0, this means adding &#8212; :require => false &#8212; inside Gemfile entry as follows.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Gemfile</span>
group <span style="color:#ff3333; font-weight:bold;">:test</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  gem <span style="color:#996600;">'mocha'</span>, <span style="color:#ff3333; font-weight:bold;">:require</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>And then adding following line at the bottom of test/test_helper.rb:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># test_helper.rb</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'mocha'</span></pre></div></div>



<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.tatvartha.com/2011/03/mocha-unexpected-invocation-errors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing RMagick gem on Mac OSX</title>
		<link>http://www.tatvartha.com/2011/03/installing-rmagick-gem-on-mac-osx/</link>
		<comments>http://www.tatvartha.com/2011/03/installing-rmagick-gem-on-mac-osx/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 04:41:36 +0000</pubDate>
		<dc:creator>Sharad</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[rmagick]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.tatvartha.com/?p=468</guid>
		<description><![CDATA[Commands for installing image-magick package and rmagick gem on max osx: sudo port install tiff -macosx imagemagick +q8 +gs +wmf sudo gem install rmagick Reference: http://rmagick.rubyforge.org/install-osx.html No related posts. Related posts brought to you by Yet Another Related Posts Plugin.


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Commands for installing image-magick package and rmagick gem on max osx:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> tiff <span style="color: #660033;">-macosx</span> imagemagick +q8 +<span style="color: #c20cb9; font-weight: bold;">gs</span> +wmf
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> rmagick</pre></div></div>

<p>Reference: <a href="http://rmagick.rubyforge.org/install-osx.html">http://rmagick.rubyforge.org/install-osx.html</a></p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.tatvartha.com/2011/03/installing-rmagick-gem-on-mac-osx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ActiveRecord::MissingAttributeError: missing attribute &#8212; a bug or a feature?</title>
		<link>http://www.tatvartha.com/2011/03/activerecordmissingattributeerror-missing-attribute-a-bug-or-a-features/</link>
		<comments>http://www.tatvartha.com/2011/03/activerecordmissingattributeerror-missing-attribute-a-bug-or-a-features/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 02:07:49 +0000</pubDate>
		<dc:creator>Sharad</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.tatvartha.com/?p=464</guid>
		<description><![CDATA[Sooner or later, the need arises to assign default values to model attributes. In rails this is usually done in model&#8217;s after_initialize() with a new_record? guard. Something like: class User def after_initialize if new_record? self.country = &#34;US&#34; end end end This initializes the object with proper default so the UI form gets properly populated and [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p><img src="http://4.bp.blogspot.com/_uyrxeugtbV0/RmlE-LeMZfI/AAAAAAAABII/JW3gs6QO3qw/s320/irannVVV.JPG" style="margin: 10px; height: 150px;"/></p>
<p>Sooner or later, the need arises to assign default values to model attributes. In rails this is usually done in model&#8217;s after_initialize() with a new_record? guard.</p>
<p>Something like:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> User
  <span style="color:#9966CC; font-weight:bold;">def</span> after_initialize
    <span style="color:#9966CC; font-weight:bold;">if</span> new_record?
      <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">country</span> = <span style="color:#996600;">&quot;US&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This initializes the object with proper default so the UI form gets properly populated and the database gets proper default if user hasn&#8217;t overridden it.</p>
<p>Sometimes, you realize that you have (pre-existing?) objects in database that also need the same default if the current value is nil. In such case, you may modify your initializer like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> User
  <span style="color:#9966CC; font-weight:bold;">def</span> after_initialize
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">country</span> <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#996600;">&quot;US&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This works for both scenarios: User.new and User.find.</p>
<p>However, it introduces a behavior that may not be apparant immediately.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ script<span style="color: #000000; font-weight: bold;">/</span>console
ree<span style="color: #000000; font-weight: bold;">&gt;</span> User.find<span style="color: #7a0874; font-weight: bold;">&#40;</span>u.id<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  User Load <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.9ms<span style="color: #7a0874; font-weight: bold;">&#41;</span>   SELECT <span style="color: #000000; font-weight: bold;">*</span> FROM <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">users</span><span style="color: #000000; font-weight: bold;">`</span> WHERE <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">users</span><span style="color: #000000; font-weight: bold;">`</span>.<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">id</span><span style="color: #000000; font-weight: bold;">`</span> = <span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> 
ree<span style="color: #000000; font-weight: bold;">&gt;</span> User.exists?<span style="color: #7a0874; font-weight: bold;">&#40;</span>:<span style="color: #c20cb9; font-weight: bold;">id</span> =<span style="color: #000000; font-weight: bold;">&gt;</span> u.id<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  RateSearch Load <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.6ms<span style="color: #7a0874; font-weight: bold;">&#41;</span>   SELECT <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">users</span><span style="color: #000000; font-weight: bold;">`</span>.id FROM <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">users</span><span style="color: #000000; font-weight: bold;">`</span> WHERE <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">users</span><span style="color: #000000; font-weight: bold;">`</span>.<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">id</span><span style="color: #000000; font-weight: bold;">`</span> = <span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> LIMIT <span style="color: #000000;">1</span>
ActiveRecord::MissingAttributeError: missing attribute: country
<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>prj<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>User.rb:<span style="color: #000000;">3</span>:<span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span>after_initialize<span style="color: #ff0000;">'</span></pre></div></div>

<p>A closer look reveals that ActiveRecord tries to be smart and only fetch &#8216;id&#8217; column when performing Model.exists? call.</p>
<p>Many people have tripped this and logged it as <a href="https://rails.lighthouseapp.com/projects/8994/tickets/3165-activerecordmissingattributeerror-after-update-to-rails-v-234">a bug</a>. The report has been silently ignored, and I believe, for good/performance reasons.</p>
<p>So, what do we get around it? Here&#8217;s one way.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> User
  <span style="color:#9966CC; font-weight:bold;">def</span> after_initialize
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">country</span> <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#996600;">&quot;US&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::MissingAttributeError</span>
    <span style="color:#008000; font-style:italic;"># this should only happen on Model.exists?() call. It can be safely ignored.</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>As they say, it is not a bug, it is a feature.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.tatvartha.com/2011/03/activerecordmissingattributeerror-missing-attribute-a-bug-or-a-features/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Online Regular Expression Tool</title>
		<link>http://www.tatvartha.com/2011/03/online-regular-expression-tool/</link>
		<comments>http://www.tatvartha.com/2011/03/online-regular-expression-tool/#comments</comments>
		<pubDate>Thu, 03 Mar 2011 00:14:25 +0000</pubDate>
		<dc:creator>Sharad</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[regexp]]></category>
		<category><![CDATA[regular expression]]></category>
		<category><![CDATA[rubular]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.tatvartha.com/?p=462</guid>
		<description><![CDATA[Rubular, is a tool that you may find handy when developing ruby regular expression for scraping unstructured data needs. http://rubular.com/ Good one! No related posts. Related posts brought to you by Yet Another Related Posts Plugin.


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Rubular, is a tool that you may find handy when developing ruby regular expression for scraping unstructured data needs.</p>
<p><a href="http://rubular.com/">http://rubular.com/</a></p>
<p>Good one!</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.tatvartha.com/2011/03/online-regular-expression-tool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

