<?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; ruby</title>
	<atom:link href="http://www.tatvartha.com/tag/ruby/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>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>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>
		<item>
		<title>Installing mysql gem with bundler on Snow Leopard</title>
		<link>http://www.tatvartha.com/2010/10/installing-mysql-gem-with-bundler-on-snow-leopard/</link>
		<comments>http://www.tatvartha.com/2010/10/installing-mysql-gem-with-bundler-on-snow-leopard/#comments</comments>
		<pubDate>Thu, 07 Oct 2010 23:34:12 +0000</pubDate>
		<dc:creator>Sharad</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[bundler]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[snow leopard]]></category>

		<guid isPermaLink="false">http://www.tatvartha.com/?p=454</guid>
		<description><![CDATA[Between 0.9.26, RC and final 1.0 release, bundler went thru some heavy changes with respect to command line options it supports. Luckily, twitter, forum and blogs kept everybody in the loop. The blogs, however, became obsolete quickly and even blog posts few months old don&#8217;t work with latest version of bundler. We came across this [...]


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://farm3.static.flickr.com/2450/3593686294_600ee1b7fb_z.jpg" style="float: right; margin: 10px; height: 250px;"/></p>
<p>Between 0.9.26, RC and final 1.0 release, <a href="http://gembundler.com/">bundler</a> went thru some heavy changes with respect to command line options it supports. Luckily, <a href="http://twitter.com/indirect">twitter</a>, <a href="http://groups.google.com/group/ruby-bundler">forum</a> and <a href="http://yehudakatz.com/tags/rails-3/">blogs</a> kept everybody in the loop.</p>
<p>The blogs, however, became obsolete quickly and even blog posts few months old don&#8217;t work with latest version of bundler. We came across this issue that kept is in a loop for a while.</p>
<p>Snow Leopard changed a few things with ruby and mysql gem when it came out. Most mysql installation issues are hammered out by now and are <a href="http://weblog.rubyonrails.org/2009/8/30/upgrading-to-snow-leopard">well documented</a>.</p>
<p><span id="more-454"></span><br />
Before you jump and execute following commands, make sure that you indeed have 64 bit mysql and 64 bit ruby on your machine. (If not, these instructions may not apply to your need).</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">which</span> ruby<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>xxx<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby: Mach-O <span style="color: #000000;">64</span>-bit executable x86_64
$ <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">which</span> mysql<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mysql: Mach-O <span style="color: #000000;">64</span>-bit executable x86_64</pre></div></div>

<p>Both installations should be Mach-O 64-bit x86_64 architecture.</p>
<p>In summary, installing mysql gem requires 2 things:</p>
<ul>
<li>Specifying architecture flags: ARCHFLAGS=&#8221;-arch x86_64&#8243;</li>
<li>Specify location of mysql_config to compile agains: &#8211;with-mysql-config=/usr/local/mysql/bin/mysql_config</li>
</ul>
<p>Prior to bundler, this is what you would do on snow-leopard to install mysql:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">env</span> <span style="color: #007800;">ARCHFLAGS</span>=<span style="color: #ff0000;">&quot;-arch x86_64&quot;</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> mysql <span style="color: #660033;">--</span> <span style="color: #660033;">--with-mysql-config</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mysql_config</pre></div></div>

<p>With bundler, there is no <a href="http://gembundler.com/man/bundle.1.html">command line option</a> that I could find that I can pass to &#8220;bundle install&#8221; command. Having been in the loop around bundler, I knew that such OS specific options don&#8217;t go in Gemfile and have to be specified in user specific files such as ~/.bundle/config file. The official website for <a href="http://gembundler.com/">gem-bundler</a> doesn&#8217;t have any mention of this (is it because we need to keep things simple for people just getting upto speed with bundler?).</p>
<p>Bundler has a feature which allow specifying build options as documented <a href="http://gembundler.com/man/bundle-config.1.html">here</a>. So, I did this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ bundle config build.mysql <span style="color: #660033;">--with-mysql-config</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mysql_config</pre></div></div>

<p>This updated my ~/.bundle/config with proper information that it will need for &#8220;bundle install&#8221; command. It make sense to keep this in ~/ folder and not my project folder since it applies only to my environment and it applies to all projects on this machine.</p>
<p>With this, doing &#8220;bundle install&#8221; still doesn&#8217;t install mysql properly. Comparing this to the pre-bundler command, it solves one issue. The ARCHFLAGS still need to be available for &#8220;bundle install&#8221;. With some leap of faith, I set an environment variable to this effect:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">ARCHFLAGS</span>=<span style="color: #ff0000;">&quot;-arch x86_64&quot;</span>
<span style="color: #666666; font-style: italic;"># should this go in my .bash_profile (so that mysql installs fine always, for all projects?</span>
<span style="color: #666666; font-style: italic;"># And I don't have to remember to set this each time I do a fresh bundle install.</span></pre></div></div>

<p>And voila, &#8220;bundle install&#8221; installs mysql correctly.</p>
<p>Bundler is stable now and is making everybody&#8217;s life much much easier. It isn&#8217;t changing as fast and so this blog post won&#8217;t be obsolete too soon <img src='http://www.tatvartha.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </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/2010/10/installing-mysql-gem-with-bundler-on-snow-leopard/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Stick with ERB or move to Haml</title>
		<link>http://www.tatvartha.com/2009/06/stick-with-erb-or-move-to-haml/</link>
		<comments>http://www.tatvartha.com/2009/06/stick-with-erb-or-move-to-haml/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 15:03:34 +0000</pubDate>
		<dc:creator>Sharad</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[erb]]></category>
		<category><![CDATA[haml]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://www.tatvartha.com/?p=174</guid>
		<description><![CDATA[Haml is gaining popularity in Rails community. It claims higher productivity compared to defacto ERB templating. Not everybody agrees though. I see 2 short-term problem with haml. ERB is similar to it pre-decessor and hence easier to learn. Compared to JSP etc. ERB is similar, you still see lots of HTML tag with interleaved ruby [...]


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://haml.hamptoncatlin.com//images/lukas/hamllogo.gif" style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; DISPLAY: inline; FLOAT: right; BORDER-LEFT: #000000 1px solid; WIDTH: 206px; BORDER-BOTTOM: #000000 1px solid; HEIGHT: 199px" height="30" width="28"/> <a href="http://haml.hamptoncatlin.com/">Haml</a> is gaining popularity in Rails community. It claims higher productivity compared to defacto <a href="http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/">ERB templating</a>. <a href="http://groups.google.com/group/spree-user/browse_thread/thread/e1a66827e3d14f81?hl=en">Not</a> everybody agrees though. I see 2 short-term problem with haml.</p>
<ol>
<li>ERB is similar to it pre-decessor and hence easier to learn. Compared to JSP etc. ERB is similar, you still see lots of HTML tag with interleaved ruby (or Java). Although verbose, it is closer to how your HTML would finally look like.</li>
<li>If your team has a dedicated HTML programmer (Designer as we may call them). These folks are very good at plain HTML and don&#8217;t want the trouble of converting files and having all the plumbing around when working. It is not efficient for them.</li>
</ol>
<p>Despite this, I see Haml as valid alternative for following reasons:</p>
<p> <span id="more-174"></span>
<ul>
<li>Its been 2 days since I started using Haml. Obviously, I have yet to higher gain productivity but tools like <a href="http://wiki.rubyonrails.org/howtos/templates/haml">html2haml</a> help a lot with the transition. I am beginning to see that I am not far behind, in terms of productivity, compared to ERb already.</li>
<li>Especially if you don&#8217;t have a dedicated Designer/HTML programmer on your team, haml gives you another shot at productivity.</li>
<li>I am not sure if this is a good idea but you can have both on the same project, but it sure does work. In fact, you can even have layouts, partials and your main page in different templating engine. Atleast, it lowers the barrier to get started.</li>
<li>Haml gets ugly when there is too much html nesting. This is a good thing since it encourages breaking your view into partials and making it modular.</li>
<li>Haml also promotes better view design by making divs/ids/classes most concise. If you are still using tables a lot, you may find yourself using divs with haml.</li>
</ul>
<p>Try it out. It&#8217;s not that bad.</p>
<p>Enjoy!</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/2009/06/stick-with-erb-or-move-to-haml/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rails Following Core development</title>
		<link>http://www.tatvartha.com/2009/06/rails-following-core-development/</link>
		<comments>http://www.tatvartha.com/2009/06/rails-following-core-development/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 14:36:51 +0000</pubDate>
		<dc:creator>Sharad</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://www.tatvartha.com/?p=173</guid>
		<description><![CDATA[If you are a passionate ruby/rails developer, you ought to be following the discussion at rubyonrails-core. Why? because the discussion (like this) that goes on about how to fix current deficiencies are really really exciting. It not only explains what the creators of the framework had in mind when designing bits and pieces and why [...]


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 a passionate ruby/rails developer, you ought to be following the discussion at <a href="http://groups.google.com/group/rubyonrails-core">rubyonrails-core</a>. Why? because the discussion (like <a href="http://groups.google.com/group/rubyonrails-core/browse_thread/thread/3b6818496d0d07f1?hl=en">this</a>) that goes on about how to fix current deficiencies are really really exciting. It not only explains what the creators of the framework had in mind when designing bits and pieces and why and why not something should be changed. Whether or not something gets accepted into the framework, it does reveal the full-truth behind the correct usability of a feature.</p>
<p>Great stuff. Enjoy!</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/2009/06/rails-following-core-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

