<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>Sikachu!'s Blog</title>
	
	<link>http://sikachu.com</link>
	<description>I'm a Ruby on Rails / jQuery web developer. Follow me at @sikachu</description>
	<lastBuildDate>Sat, 25 Dec 2010 15:13:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/SikachuBlog" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="sikachublog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Attack of the Droids</title>
		<link>http://sikachu.com/2010/12/attack-of-the-droids/</link>
		<comments>http://sikachu.com/2010/12/attack-of-the-droids/#comments</comments>
		<pubDate>Sat, 25 Dec 2010 15:13:27 +0000</pubDate>
		<dc:creator>Sikachu!</dc:creator>
				<category><![CDATA[Gadgets]]></category>
		<category><![CDATA[Garbage]]></category>
		<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://sikachu.com/?p=766</guid>
		<description><![CDATA[(อ้างถึง http://www.isriya.com/node/3426/attack-of-the-droids) TL;DR You bought an Android phone from store today, it might be outdated by next week. Also, you have to do a lot of comparison as you&#8217;re buying a PC. ผมมองว่าการที่โทรศัพท์มือถือ Android ออกรุ่นใหม่ๆ เยอะมาก จากหลายๆ ค่าย มันทำให้เรารู้สึกว่าเครื่องเราดูตกรุ่นเร็วขึ้น อย่างเช่นสมมุติคุณซื้อ HTC Hero มา ผ่านไปสามสี่เดือนมีเครื่องรุ่นใหม่ออกมาซะแล้ว ทำอะไรได้มากกว่า และอาจจะรองรับ ROM รุ่นใหม่กว่าได้ ถ้าคุณยังต้องการที่จะได้รับประสบการณ์ที่ดีที่สุดจากการใช้ Android คุณก็คงต้องเปลี่ยนเครื่องใหม่ กลับกัน ถ้าโทรศัพท์ที่ใช้ Android เปลี่ยนใหม่ [...]]]></description>
			<content:encoded><![CDATA[<p>(อ้างถึง <a href="" target="_blank">http://www.isriya.com/node/3426/attack-of-the-droids</a>)</p>
<p><strong>TL;DR</strong> You bought an Android phone from store today, it might be outdated by next week. Also, you have to do a lot of comparison as you&#8217;re buying a PC.</p>
<p>ผมมองว่าการที่โทรศัพท์มือถือ Android ออกรุ่นใหม่ๆ เยอะมาก จากหลายๆ ค่าย มันทำให้เรารู้สึกว่าเครื่องเราดูตกรุ่นเร็วขึ้น อย่างเช่นสมมุติคุณซื้อ HTC Hero มา ผ่านไปสามสี่เดือนมีเครื่องรุ่นใหม่ออกมาซะแล้ว ทำอะไรได้มากกว่า และอาจจะรองรับ ROM รุ่นใหม่กว่าได้ ถ้าคุณยังต้องการที่จะได้รับประสบการณ์ที่ดีที่สุดจากการใช้ Android คุณก็คงต้องเปลี่ยนเครื่องใหม่</p>
<p>กลับกัน ถ้าโทรศัพท์ที่ใช้ Android เปลี่ยนใหม่ ออกเป็นรายปี หรือรายครึ่งปี คุณซื้อโทรศัพท์เครื่องหนึ่งคุณก็จะมั่นใจว่ามันจะเป็นเครื่องที่ดีที่สุดไปอีกซัก 6 เดือน &#8211; 1 ปี ก่อนที่คุณจะเห็นเครื่องรุ่นใหม่ที่น่าสนใจจะซื้อ</p>
<p>คิดว่า Android คงอยากจะเดินไปทางเดียวกับ Symbian ในการที่เพิ่มจำนวนของเครื่องที่ใช้ platform นี้ให้มากที่สุด หารู้ไม่ว่ามันกลับเพิ่มความสับสนให้ผู้ใช้เป็นอย่างมากในการซื้อเครื่อง เพราะคุณจะต้องมานั่งเทียบ spec แบบซื้อคอมพิวเตอร์เครื่องหนึ่งเลยทีเดียว แทนที่จะไม่ต้องคิดมากแล้วซื้อแค่ &#8220;รุ่นที่ใหม่ที่สุด&#8221; ไปเลย</p>
<img src="http://feeds.feedburner.com/~r/SikachuBlog/~4/f9us8sJ74qE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sikachu.com/2010/12/attack-of-the-droids/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hoptoad ❤ Heroku</title>
		<link>http://sikachu.com/2010/12/hoptoad-loves-heroku/</link>
		<comments>http://sikachu.com/2010/12/hoptoad-loves-heroku/#comments</comments>
		<pubDate>Wed, 15 Dec 2010 14:14:56 +0000</pubDate>
		<dc:creator>Sikachu!</dc:creator>
				<category><![CDATA[My Project]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Heroku]]></category>
		<category><![CDATA[hoptoad]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://sikachu.com/?p=762</guid>
		<description><![CDATA[Recently, I&#8217;ve started to migrate my application to Heroku. While most of the functionalities are there, one of the thing I was missing is Hoptoad&#8216;s deploy tracking, as you cannot add a deploy hook to call Rake task as you normally do. After I found that Heroku actually supports HTTP Post hook, I spend 2 [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I&#8217;ve started to migrate my application to <a href="http://heroku.com/" target="_blank">Heroku</a>. While most of the functionalities are there, one of the thing I was missing is <a href="http://hoptoadapp.com/pages/home" target="_blank">Hoptoad</a>&#8216;s <a href="https://hoptoadapp.com/account/new?source=home_top_button" target="_blank">deploy tracking</a>, as you cannot add a deploy hook to call Rake task as you normally do.</p>
<p>After I found that Heroku actually supports <a href="http://docs.heroku.com/deploy-hooks#http-post-hook" target="_blank">HTTP Post hook</a>, I spend 2 hours reading API and hacking into <a href="http://github.com/thoughtbot/hoptoad_notifier" target="_blank">hoptoad_notifier</a> code. And now, I would like to presents you <a href="http://hoptoad-loves.heroku.com/" target="_blank">Hoptoad ❤ Heroku</a>.</p>
<h3>What is it?</h3>
<p>It&#8217;s a middleware application that will converts parameters from Heroku&#8217;s HTTP Post hook to parameters that Hoptoad would understand.</p>
<h3>How to use it?</h3>
<p>You just add the HTTP Post deploy hook to your Heroku project. It should look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">heroku addons:add deployhooks:http url=http:<span style="color:#006600; font-weight:bold;">//</span>hoptoad<span style="color:#006600; font-weight:bold;">-</span>loves.<span style="color:#9900CC;">heroku</span>.<span style="color:#9900CC;">com</span><span style="color:#006600; font-weight:bold;">/</span>YOUR_HOPTOAD_API_KEY<span style="color:#006600; font-weight:bold;">/</span>YOUR_RACK_ENV</pre></div></div>

<p>You&#8217;d then substitute <code>YOUR_HOPTOAD_API_KEY</code> and <code>YOUR_RACK_ENV</code> to match your configuration.</p>
<p>You can find more information on <a href="http://github.com/sikachu/hoptoad-loves-heroku" target="_blank">GitHub</a> or the site itself: <a href="http://hoptoad-loves.heroku.com/" target="_blank">http://hoptoad-loves.heroku.com/</a></p>
<p>(Please note that Hoptoad deploy tracking feature is only available in their paid plans.)</p>
<hr />
<p>I hope you found it useful for your project. All of the code is hosted on <a href="http://github.com/sikachu/hoptoad-loves-heroku" target="_blank">GitHub</a>. Contributions and feedbacks are always welcome.</p>
<img src="http://feeds.feedburner.com/~r/SikachuBlog/~4/XXSINy61xCM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sikachu.com/2010/12/hoptoad-loves-heroku/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My Devise custom routes</title>
		<link>http://sikachu.com/2010/12/my-devise-custom-routes/</link>
		<comments>http://sikachu.com/2010/12/my-devise-custom-routes/#comments</comments>
		<pubDate>Mon, 13 Dec 2010 15:40:42 +0000</pubDate>
		<dc:creator>Sikachu!</dc:creator>
				<category><![CDATA[My Idea]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Devise]]></category>
		<category><![CDATA[Rails 3]]></category>

		<guid isPermaLink="false">http://sikachu.com/?p=757</guid>
		<description><![CDATA[Since the release of Rails 3, I&#8217;ve been using Devise as my authentication gem. While it delivers everything I need, its default route doesn&#8217;t look really good when I have only one authentication scope, such as User. The default route when you&#8217;re using devise_for :users will look like this: new_user_session GET /users/sign_in(.:format) {:action=&#62;&#34;new&#34;, :controller=&#62;&#34;devise/sessions&#34;} user_session [...]]]></description>
			<content:encoded><![CDATA[<p>Since the release of Rails 3, I&#8217;ve been using <a href="http://github.com/plataformatec/devise" target="_blank">Devise</a> as my authentication gem. While it delivers everything I need, its default route doesn&#8217;t look really good when I have only one authentication scope, such as <code>User</code>. The default route when you&#8217;re using <code>devise_for :users</code> will look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="console" style="font-family:monospace;">         new_user_session GET    /users/sign_in(.:format)          {:action=&gt;&quot;new&quot;, :controller=&gt;&quot;devise/sessions&quot;}
             user_session POST   /users/sign_in(.:format)          {:action=&gt;&quot;create&quot;, :controller=&gt;&quot;devise/sessions&quot;}
     destroy_user_session GET    /users/sign_out(.:format)         {:action=&gt;&quot;destroy&quot;, :controller=&gt;&quot;devise/sessions&quot;}
            user_password POST   /users/password(.:format)         {:action=&gt;&quot;create&quot;, :controller=&gt;&quot;devise/passwords&quot;}
        new_user_password GET    /users/password/new(.:format)     {:action=&gt;&quot;new&quot;, :controller=&gt;&quot;devise/passwords&quot;}
       edit_user_password GET    /users/password/edit(.:format)    {:action=&gt;&quot;edit&quot;, :controller=&gt;&quot;devise/passwords&quot;}
                          PUT    /users/password(.:format)         {:action=&gt;&quot;update&quot;, :controller=&gt;&quot;devise/passwords&quot;}
 cancel_user_registration GET    /users/cancel(.:format)           {:action=&gt;&quot;cancel&quot;, :controller=&gt;&quot;devise/registrations&quot;}
        user_registration POST   /users(.:format)                  {:action=&gt;&quot;create&quot;, :controller=&gt;&quot;devise/registrations&quot;}
    new_user_registration GET    /users/sign_up(.:format)          {:action=&gt;&quot;new&quot;, :controller=&gt;&quot;devise/registrations&quot;}
   edit_user_registration GET    /users/edit(.:format)             {:action=&gt;&quot;edit&quot;, :controller=&gt;&quot;devise/registrations&quot;}
                          PUT    /users(.:format)                  {:action=&gt;&quot;update&quot;, :controller=&gt;&quot;devise/registrations&quot;}
                          DELETE /users(.:format)                  {:action=&gt;&quot;destroy&quot;, :controller=&gt;&quot;devise/registrations&quot;}
        user_confirmation POST   /users/confirmation(.:format)     {:action=&gt;&quot;create&quot;, :controller=&gt;&quot;devise/confirmations&quot;}
    new_user_confirmation GET    /users/confirmation/new(.:format) {:action=&gt;&quot;new&quot;, :controller=&gt;&quot;devise/confirmations&quot;}
                          GET    /users/confirmation(.:format)     {:action=&gt;&quot;show&quot;, :controller=&gt;&quot;devise/confirmations&quot;}</pre></div></div>

<p>As you can see, all of the routes are defined under <code>/users</code> path. So, I&#8217;ve modified my devise route block to this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">devise_for <span style="color:#ff3333; font-weight:bold;">:users</span>, <span style="color:#ff3333; font-weight:bold;">:skip</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:registrations</span>, <span style="color:#ff3333; font-weight:bold;">:sessions</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#008000; font-style:italic;"># devise/registrations</span>
  get <span style="color:#996600;">'signup'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'devise/registrations#new'</span>, <span style="color:#ff3333; font-weight:bold;">:as</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:new_user_registration</span>
  post <span style="color:#996600;">'signup'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'devise/registrations#create'</span>, <span style="color:#ff3333; font-weight:bold;">:as</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:user_registration</span>
  get <span style="color:#996600;">'users/cancel'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'devise/registrations#cancel'</span>, <span style="color:#ff3333; font-weight:bold;">:as</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:cancel_user_registration</span>
  get <span style="color:#996600;">'users/edit'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'devise/registrations#edit'</span>, <span style="color:#ff3333; font-weight:bold;">:as</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:edit_user_registration</span>
  put <span style="color:#996600;">'users'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'devise/registrations#update'</span>
  delete <span style="color:#996600;">'users/cancel'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'devise/registrations#destroy'</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># devise/sessions</span>
  get <span style="color:#996600;">'signin'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'devise/sessions#new'</span>, <span style="color:#ff3333; font-weight:bold;">:as</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:new_user_session</span>
  post <span style="color:#996600;">'signin'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'devise/sessions#create'</span>, <span style="color:#ff3333; font-weight:bold;">:as</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:user_session</span>
  get <span style="color:#996600;">'signout'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'devise/sessions#destroy'</span>, <span style="color:#ff3333; font-weight:bold;">:as</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:destroy_user_session</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Which will yield these routes:</p>

<div class="wp_syntax"><div class="code"><pre class="console" style="font-family:monospace;">    new_user_registration GET    /signup(.:format)                 {:action=&gt;&quot;new&quot;, :controller=&gt;&quot;devise/registrations&quot;}
        user_registration POST   /signup(.:format)                 {:action=&gt;&quot;create&quot;, :controller=&gt;&quot;devise/registrations&quot;}
 cancel_user_registration GET    /users/cancel(.:format)           {:controller=&gt;&quot;devise/registrations&quot;, :action=&gt;&quot;cancel&quot;}
   edit_user_registration GET    /users/edit(.:format)             {:controller=&gt;&quot;devise/registrations&quot;, :action=&gt;&quot;edit&quot;}
                    users PUT    /users(.:format)                  {:action=&gt;&quot;update&quot;, :controller=&gt;&quot;devise/registrations&quot;}
             users_cancel DELETE /users/cancel(.:format)           {:controller=&gt;&quot;devise/registrations&quot;, :action=&gt;&quot;destroy&quot;}
         new_user_session GET    /signin(.:format)                 {:action=&gt;&quot;new&quot;, :controller=&gt;&quot;devise/sessions&quot;}
             user_session POST   /signin(.:format)                 {:action=&gt;&quot;create&quot;, :controller=&gt;&quot;devise/sessions&quot;}
     destroy_user_session GET    /signout(.:format)                {:action=&gt;&quot;destroy&quot;, :controller=&gt;&quot;devise/sessions&quot;}
            user_password POST   /users/password(.:format)         {:action=&gt;&quot;create&quot;, :controller=&gt;&quot;devise/passwords&quot;}
        new_user_password GET    /users/password/new(.:format)     {:action=&gt;&quot;new&quot;, :controller=&gt;&quot;devise/passwords&quot;}
       edit_user_password GET    /users/password/edit(.:format)    {:action=&gt;&quot;edit&quot;, :controller=&gt;&quot;devise/passwords&quot;}
                          PUT    /users/password(.:format)         {:action=&gt;&quot;update&quot;, :controller=&gt;&quot;devise/passwords&quot;}
        user_confirmation POST   /users/confirmation(.:format)     {:action=&gt;&quot;create&quot;, :controller=&gt;&quot;devise/confirmations&quot;}
    new_user_confirmation GET    /users/confirmation/new(.:format) {:action=&gt;&quot;new&quot;, :controller=&gt;&quot;devise/confirmations&quot;}
                          GET    /users/confirmation(.:format)     {:action=&gt;&quot;show&quot;, :controller=&gt;&quot;devise/confirmations&quot;}</pre></div></div>

<p>I think my new routes is much better. For example, I think user would prefer a path to sign in page to be <code>/signin</code> than <code>/users/sign_in</code>, as it more memorable.</p>
<p>I hope this post would inspire you more about customize Devise&#8217;s routes to fit your need.</p>
<img src="http://feeds.feedburner.com/~r/SikachuBlog/~4/zdtbujCgRj4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sikachu.com/2010/12/my-devise-custom-routes/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>`method_missing` call stack in Ruby</title>
		<link>http://sikachu.com/2010/11/method-missing-call-stack-in-ruby/</link>
		<comments>http://sikachu.com/2010/11/method-missing-call-stack-in-ruby/#comments</comments>
		<pubDate>Tue, 23 Nov 2010 05:56:52 +0000</pubDate>
		<dc:creator>Sikachu!</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://sikachu.com/?p=751</guid>
		<description><![CDATA[Just found out something cool from reading &#8220;Don’t Know Metaprogramming In Ruby?&#8221; from RubyLearning blog. Consider this code snippet: class Person end &#160; class Student &#60; Person end &#160; class HighSchoolStudent &#60; Student end If you&#8217;re calling some method that&#8217;s undefined, let&#8217;s say we&#8217;re calling HighSchoolStudent#name Ruby will try to call the method in this [...]]]></description>
			<content:encoded><![CDATA[<p>Just found out something cool from reading &#8220;<a href="http://rubylearning.com/blog/2010/11/23/dont-know-metaprogramming-in-ruby/" target="_blank">Don’t Know Metaprogramming In Ruby?</a>&#8221; from RubyLearning blog. Consider this code snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Person
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> Student <span style="color:#006600; font-weight:bold;">&lt;</span> Person
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> HighSchoolStudent <span style="color:#006600; font-weight:bold;">&lt;</span> Student
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>If you&#8217;re calling some method that&#8217;s undefined, let&#8217;s say we&#8217;re calling <code>HighSchoolStudent#name</code> Ruby will try to call the method in this order:</p>
<ol>
<li>HighSchoolStudent#name</li>
<li>Student#name</li>
<li>Person#name</li>
<li>Object#name</li>
<li>Kernel#name</li>
<li>BasicObject#name</li>
<li>HighSchoolStudent#method_missing</li>
<li>Student#method_missing</li>
<li>Person#method_missing</li>
<li>Object#method_missing</li>
<li>Kernel#method_missing</li>
<li>BasicObject#method_missing</li>
</ol>
<p>From this example, you can see that not explicitly define method and capture it in <code>method_missing</code> might not be good in terms of the performance. So, what should you do?</p>
<p>I think the best way to do it, if you know that this method will get called again, would be define the &#8216;real&#8217; method after it gets called. That will reduce the call stack starting from the second run, resulting in faster code.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Let say we're defining method for #*_with_id here</span>
<span style="color:#9966CC; font-weight:bold;">def</span> method_missing<span style="color:#006600; font-weight:bold;">&#40;</span>name, <span style="color:#006600; font-weight:bold;">*</span>args<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">super</span> <span style="color:#9966CC; font-weight:bold;">if</span> name !~ <span style="color:#006600; font-weight:bold;">/</span>_with_id$<span style="color:#006600; font-weight:bold;">/</span>
&nbsp;
  define_method <span style="color:#996600;">&quot;#{name}_with_id&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    instance_variable_get<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:id</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;-&quot;</span> <span style="color:#006600; font-weight:bold;">+</span> instance_variable_get<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Hope this will make your code run faster, while still DRY.</p>
<img src="http://feeds.feedburner.com/~r/SikachuBlog/~4/SSHYWg0EvJc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sikachu.com/2010/11/method-missing-call-stack-in-ruby/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Gems — Follow up from my talk at #BarcampBKK4</title>
		<link>http://sikachu.com/2010/10/gems-barcampbkk4/</link>
		<comments>http://sikachu.com/2010/10/gems-barcampbkk4/#comments</comments>
		<pubDate>Fri, 29 Oct 2010 16:46:44 +0000</pubDate>
		<dc:creator>Sikachu!</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[BarcampBKK4]]></category>

		<guid isPermaLink="false">http://sikachu.com/?p=749</guid>
		<description><![CDATA[I think I should noted down two gems that I mentioned in my talk. Omniauth — a middleware that help you authenticate user to various SSO sites, such as Facebook Connect, Twitter, Google Account Devise — fully-functional authentication system. If you write an app that need authentication, this should be the solution for you. Writing [...]]]></description>
			<content:encoded><![CDATA[<p>I think I should noted down two gems that I mentioned in my talk.</p>
<ul>
<li><strong><a href="http://github.com/intridea/omniauth" target="_blank">Omniauth</a></strong> — a middleware that help you authenticate user to various SSO sites, such as Facebook Connect, Twitter, Google Account</li>
<li><strong><a href="http://github.com/plataformatec/devise" target="_blank">Devise</a></strong> — fully-functional authentication system. If you write an app that need authentication, this should be the solution for you. Writing your own authentication is discourage now. More on this later.</li>
</ul>
<p>I feel like I was saying 3 of them, but I can&#8217;t remember the other one. Anyway, don&#8217;t forget to dig into <a href="http://www.rubygems.org/" target="_blank">RubyGems</a> to find out some great gem to use in your project.</p>
<img src="http://feeds.feedburner.com/~r/SikachuBlog/~4/W1lRZuvaZaQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sikachu.com/2010/10/gems-barcampbkk4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>10 Things you should know about Ruby — #BarcampBKK4</title>
		<link>http://sikachu.com/2010/10/10-things-you-should-know-about-ruby/</link>
		<comments>http://sikachu.com/2010/10/10-things-you-should-know-about-ruby/#comments</comments>
		<pubDate>Sun, 24 Oct 2010 15:20:28 +0000</pubDate>
		<dc:creator>Sikachu!</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[BarcampBKK4]]></category>

		<guid isPermaLink="false">http://sikachu.com/?p=743</guid>
		<description><![CDATA[I&#8217;ve done a talk about Ruby in Barcamp Bangkok 4 on Oct 24. Here is the slide in case someone want it. 10 things you should know about ruby You can download it if you want. This slide is CC-BY-NC-SA (as some photo I use require share-alike license.) One good question actually was the difference [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve done a talk about Ruby in Barcamp Bangkok 4 on Oct 24. Here is the slide in case someone want it.</p>
<div style="width:425px" id="__ss_5544219"><strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/sikachu/10-things-you-should-know-about-ruby" title="10 things you should know about ruby">10 things you should know about ruby</a></strong><object id="__sse5544219" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=10thingsyoushouldknowaboutruby-101024103648-phpapp01&#038;stripped_title=10-things-you-should-know-about-ruby&#038;userName=sikachu" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed name="__sse5544219" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=10thingsyoushouldknowaboutruby-101024103648-phpapp01&#038;stripped_title=10-things-you-should-know-about-ruby&#038;userName=sikachu" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object></div>
<p>You can <a href="http://www.slideshare.net/sikachu/10-things-you-should-know-about-ruby/download" target="_blank">download</a> it if you want. This slide is <a href="http://creativecommons.org/licenses/by-nc-sa/2.0/" target="_blank">CC-BY-NC-SA</a> (as some photo I use require share-alike license.)</p>
<p>One good question actually was the difference between <code>module</code> and <code>class</code>. Actually, it just that simple — you cannot create object from a module.</p>
<p><code>Module</code> exists in Ruby to help you DRY up your code.</p>
<p>When you write several classes which have the same functionality, you better take that portion of the code out and put it in a module and <code>include</code> them back into your classes. That&#8217;s actually something Ruby coder loves to do — DRY up your code, and make it more maintainable.</p>
<hr />
<p>If you have any more question, feel free to post them in the comment section. I actually fumbled on my word a lot, because I didn&#8217;t get enough sleep last night. If you also want me to clearify something up, please let me know. Anyway, I hope you enjoyed it.</p>
<img src="http://feeds.feedburner.com/~r/SikachuBlog/~4/V5xz8eQ_vOo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sikachu.com/2010/10/10-things-you-should-know-about-ruby/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>My predictions on Apple’s ‘Back to Mac’ event</title>
		<link>http://sikachu.com/2010/10/my-predictions-on-apples-back-to-mac-event/</link>
		<comments>http://sikachu.com/2010/10/my-predictions-on-apples-back-to-mac-event/#comments</comments>
		<pubDate>Wed, 20 Oct 2010 15:42:21 +0000</pubDate>
		<dc:creator>Sikachu!</dc:creator>
				<category><![CDATA[Apple]]></category>

		<guid isPermaLink="false">http://sikachu.com/?p=741</guid>
		<description><![CDATA[Well, after all the rumors, I can&#8217;t helped but predict something that Mr. Jobs will reveal today: Macbook Air Refresh I think this should definitely come, after several leaks of the machine. I think Apple will still offer the machine in both 11&#8243; and 13&#8243;, but several parts in it would be proprietary and not [...]]]></description>
			<content:encoded><![CDATA[<p>Well, after all the rumors, I can&#8217;t helped but predict something that Mr. Jobs will reveal today:</p>
<h3>Macbook Air Refresh</h3>
<p>I think this should definitely come, after several leaks of the machine. I think Apple will still offer the machine in both 11&#8243; and 13&#8243;, but several parts in it would be proprietary and not user-replaceable. I also predicting that the 11&#8243; version will have the same resolution as the current 13&#8243; Macbook pro — delivers more resolution than it predecessor.</p>
<h3>Macbook Pro Refresh</h3>
<p>It makes sense as the current Macbook Pro are reaching the end of cycle. I expecting just a speed bump from the previous version — making the top of the line to be 2.8 GHz Core i7-640, which can be turbo-boosted to 3.46 GHz. I really saw this one coming from reading <a href="http://www.engadget.com/2010/05/30/leaked-intel-roadmap-reveals-six-new-notebook-cpus-for-2010-bet/" target="_blank">Engadget&#8217;s post</a> a while back. </p>
<h3>Mac OS X 10.7 &#8220;Lion&#8221;</h3>
<p>I think we&#8217;ll able to see the &#8220;sneak-peak&#8221; version of the OS which introduce several improvements from the current Snow Leopard. I&#8217;m expecting a new finder interface, with the new iChat that can talk to iPhone via FaceTime.</p>
<h3>iLife &#8217;11</h3>
<p>This one will be announced for sure, and I think we might seeing a new application added to the suite. I think this will be available right after the keynote.</p>
<h3>White iPhone 4</h3>
<p>I put it here just for Christ&#8217;s sake — it has been too long. Anyway, I think Apple could use a little moment to talk about it, even the event&#8217;s name is &#8220;Back to Mac&#8221;. I don&#8217;t know what would be a good time to talk about it if they&#8217;re going to <a href="http://www.mobilesdna.com/news/white-iphone-4-finally-releasing-before-christmas-hinted-steve-jobes" target="_blank">launch the phone before Christmas</a>.</p>
<hr />
<p>That&#8217;s it for my prediction. Be prepared to tuned in to Apple&#8217;s streaming at midnight tonight! (GMT+7)</p>
<img src="http://feeds.feedburner.com/~r/SikachuBlog/~4/ojbvuYwYMB4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sikachu.com/2010/10/my-predictions-on-apples-back-to-mac-event/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RailsCamp (Thailand) 2010</title>
		<link>http://sikachu.com/2010/10/railscamp-thailand-2010/</link>
		<comments>http://sikachu.com/2010/10/railscamp-thailand-2010/#comments</comments>
		<pubDate>Wed, 20 Oct 2010 06:52:35 +0000</pubDate>
		<dc:creator>Sikachu!</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://sikachu.com/?p=739</guid>
		<description><![CDATA[เพิ่งทราบข่าวมาวันนี้ว่าที่ประเทศไทย จะมีคนจัดงาน RailsCamp แล้ว! RailsCamp (Thailand) 2010 ดีใจ + ตกใจนิดหน่อย เพราะเป็นโปรเจคที่คิดไว้ตั้งแต่เมื่อ 2-3 ปีที่แล้ว ตั้งแต่เมื่อตอนที่เขียน Rails ใหม่ๆ ว่าอยากให้มีงานที่เป็น Ruby on Rails Community ของคนไทย &#8230; ในเมื่อมีคนทำแล้ว ผมก็ขอสนับสนุนเต็มทีครับ ผมคงจะเตรียมเรื่องไปพูดนิดหน่อย ไม่แน่ใจเหมือนกันว่าเรื่องอะไร แต่ถ้าดูจาก Schedule ปัจจุบัน อาจจะได้พูดเรื่อง Behavior Driven Development using Cucumber หรือไม่ก็ Devise เพราะว่าเรื่องใหญ่ๆ อย่าง Rails 3 กับ Ruby 1.9 ได้อาจารย์ @rawitat กับคุณ @neokain พูดไปแล้ว ไปเจอกันโลด วันเสาร์ที่ 13 พฤศจิกายน 2553 [...]]]></description>
			<content:encoded><![CDATA[<p>เพิ่งทราบข่าวมาวันนี้ว่าที่ประเทศไทย จะมีคนจัดงาน RailsCamp แล้ว!</p>
<p><a href="http://www.thairor.com/2010/10/blog-post.html" target="_blank">RailsCamp (Thailand) 2010</a></p>
<p>ดีใจ + ตกใจนิดหน่อย เพราะเป็นโปรเจคที่คิดไว้ตั้งแต่เมื่อ 2-3 ปีที่แล้ว ตั้งแต่เมื่อตอนที่เขียน Rails ใหม่ๆ ว่าอยากให้มีงานที่เป็น Ruby on Rails Community ของคนไทย &#8230; ในเมื่อมีคนทำแล้ว ผมก็ขอสนับสนุนเต็มทีครับ ผมคงจะเตรียมเรื่องไปพูดนิดหน่อย ไม่แน่ใจเหมือนกันว่าเรื่องอะไร แต่ถ้าดูจาก Schedule ปัจจุบัน อาจจะได้พูดเรื่อง Behavior Driven Development using Cucumber หรือไม่ก็ Devise เพราะว่าเรื่องใหญ่ๆ อย่าง Rails 3 กับ Ruby 1.9 ได้อาจารย์ <a href="http://twitter.com/rawitat" target="_blank">@rawitat</a> กับคุณ <a href="http://twitter.com/neokain" target="_blank">@neokain</a> พูดไปแล้ว <img src='http://sikachu.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>ไปเจอกันโลด วันเสาร์ที่ 13 พฤศจิกายน 2553 เวลา 9:30-17:00 น. ณ Opendream</p>
<p>ปล. ได้เวลาปัดฝุ่นโปรเจคลับแล้วสินะ <img src='http://sikachu.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/SikachuBlog/~4/YEdlMSmSKfw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sikachu.com/2010/10/railscamp-thailand-2010/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>คาดการณ์ราคา iPhone 4 ในไทย</title>
		<link>http://sikachu.com/2010/09/expected-iphone-4-price-in-thailand/</link>
		<comments>http://sikachu.com/2010/09/expected-iphone-4-price-in-thailand/#comments</comments>
		<pubDate>Thu, 16 Sep 2010 11:14:49 +0000</pubDate>
		<dc:creator>Sikachu!</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Gadgets]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[iPhone 4]]></category>

		<guid isPermaLink="false">http://sikachu.com/?p=732</guid>
		<description><![CDATA[สั้นๆ ได้ใจความ: ผมว่าราคา iPhone 4 16GB อยู่ที่ ฿21,500 และ 32GB อยู่ที่ ฿25,000 เหตุผล ช่วงนี้ข่าวคราวในเรื่องของการจำหน่าย iPhone 4 ในประเทศไทยนั้นเริ่มหนาแน่นขึ้น เนื่องจากถึงเวลาที่ Apple จะเริ่มจำหน่าย iPhone 4 ในประเทศที่เป็นกลุ่มสุดท้ายของเป้าหมาย ซึ่งข่าวลือนั้นมีตั้งแต่การที่ค่ายยักษ์ใหญ่อย่าง AIS จะมีการจำหน่าย iPhone 4 (ซึ่งก็จริง!) และการที่จะเปิดให้จองก่อน แล้วได้รับเครื่องสิ้นเดือน ก็ดูท่าจะจริงอีกเช่นกัน ถึงแม้ข่าวลือต่างๆ จะมีออกมาเยอะเท่าไรก็ตาม แต่สิ่งหนึ่งที่หลายๆ คนถามถึงแต่ไม่มีข่าวออกมาเลยนั่นคือเรื่องของราคาครับ ส่วนใหญ่แล้วจะคิดว่าราคาคงจะเท่ากว่ารุ่นเดิม หรือว่าน้อยกว่ารุ่นเดิม ตามวิธีการตั้งราคาของ Apple ประเทศไทย &#8230; ผมก็อดไม่ได้ครับ อยากลองคำนวณดูบ้างว่าถ้า iPhone 4 เข้าประเทศไทยมาแล้ว ราคาควรจะอยู่ที่เท่าไร ลองดูจากตารางอันนี้นะครับ: จะเห็นได้ว่าผมลองเอาราคาของผลิตภัณฑ์ที่เพิ่งออกใหม่ในอเมริกาบวกกับภาษี มาเทียบกับราคาขายปลีกในประเทศไทย เพื่อหาว่า Apple ใช้อัตราใดในการตั้งราคาสินค้า ซึ่งก็ได้ออกมาประมาณ [...]]]></description>
			<content:encoded><![CDATA[<p><strong>สั้นๆ ได้ใจความ:</strong> ผมว่าราคา iPhone 4 16GB อยู่ที่ ฿21,500 และ 32GB อยู่ที่ ฿25,000</p>
<h3>เหตุผล</h3>
<p>ช่วงนี้ข่าวคราวในเรื่องของการจำหน่าย iPhone 4 ในประเทศไทยนั้นเริ่มหนาแน่นขึ้น เนื่องจากถึงเวลาที่ Apple จะเริ่มจำหน่าย iPhone 4 ในประเทศที่เป็นกลุ่มสุดท้ายของเป้าหมาย ซึ่งข่าวลือนั้นมีตั้งแต่การที่ค่ายยักษ์ใหญ่อย่าง AIS จะมีการจำหน่าย iPhone 4 (ซึ่งก็จริง!) และการที่จะเปิดให้จองก่อน แล้วได้รับเครื่องสิ้นเดือน ก็ดูท่าจะจริงอีกเช่นกัน</p>
<p>ถึงแม้ข่าวลือต่างๆ จะมีออกมาเยอะเท่าไรก็ตาม แต่สิ่งหนึ่งที่หลายๆ คนถามถึงแต่ไม่มีข่าวออกมาเลยนั่นคือเรื่องของราคาครับ ส่วนใหญ่แล้วจะคิดว่าราคาคงจะเท่ากว่ารุ่นเดิม หรือว่าน้อยกว่ารุ่นเดิม ตามวิธีการตั้งราคาของ Apple ประเทศไทย &#8230; ผมก็อดไม่ได้ครับ อยากลองคำนวณดูบ้างว่าถ้า iPhone 4 เข้าประเทศไทยมาแล้ว ราคาควรจะอยู่ที่เท่าไร</p>
<p>ลองดูจากตารางอันนี้นะครับ:</p>
<p><img src="http://sikachu.com/wp-content/uploads/2010/09/Screen-shot-2553-09-16-at-18.15.57.png" alt="Screen shot 2553-09-16 at 18.15.57.png" border="0" width="484" height="297" /></p>
<p>จะเห็นได้ว่าผมลองเอาราคาของผลิตภัณฑ์ที่เพิ่งออกใหม่ในอเมริกาบวกกับภาษี มาเทียบกับราคาขายปลีกในประเทศไทย เพื่อหาว่า Apple ใช้อัตราใดในการตั้งราคาสินค้า ซึ่งก็ได้ออกมาประมาณ 32.77 บาทต่อ 1 ดอลล่าร์สหรัฐ (ในขณะที่อัตราแลกเปลี่ยนตอนนั้นอยู่ที่ประมาณ 31 บาทต่อ 1 ดอลล่าร์สหรัฐ)</p>
<p>ปกติแล้วหลักการตั้งราคาของ Apple ผมเข้าใจว่าเป็นอัตราแลกเปลี่ยน ณ ขณะนั้น บวกไปอีกประมาณ 1-2 บาท เพื่อเป็นการประกันความเสี่ยงของอัตราแลกเปลี่ยน แล้วบวกค่าขนส่งของแต่ละชิ้น &#8230; ซึ่งตอนนี้ถึงแม้อัตราแลกเปลี่ยนจะลงมาอยู่ประมาณ 29~30 บาทต่อ 1 ดอลลาร์สหรัฐแล้วก็ตาม ผมคิดว่าอัตราที่คำนวณได้นี่น่าจะใกล้เคียงอัตราที่ Apple จะใช้จริงไม่มากก็น้อยครับ</p>
<p>ว่าแต่วันเปิดตัว มีใครจะไปต่อแถวซื้อบ้างไหมครับ? ถ้าไปแล้วเจอกันทักทายกันได้นะครับ <img src='http://sikachu.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<h3>UPDATE</h3>
<p>วันนี้ตกใจมาก เพราะไปเจอว่า <a href="http://www.geeknone.com/2010/08/iphone-4-21500.html" target="_blank">Geeknone</a> ได้อัพเอาไว้ในราคาเดียวกันเป๊ะกับผมเลย แถมอัพไว้ตั้งแต่ปลายเดือนสิงหาแล้วด้วย &#8230; ยืนยันครับว่าผมไม่ได้รู้เรื่องเลยว่ามีคนกะประมาณราคาเอาไว้แล้ว + อัพบล็อกไว้ด้วยแล้ว ผมไม่ได้ลอกมานะครับ -_-&#8221;</p>
<p>แต่เอ .. คำนวณออกมาแล้วราคาเท่ากันกับที่เขาคาดเอาไว้อย่างนี้ แปลว่าความเป็นไปได้นี่มีสูงเลยสิเนี่ย 555+</p>
<img src="http://feeds.feedburner.com/~r/SikachuBlog/~4/_eBhzseBCgM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sikachu.com/2010/09/expected-iphone-4-price-in-thailand/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Possible pitfall on ActiveRecord::Base#create</title>
		<link>http://sikachu.com/2010/08/possible-pitfall-on-activerecordbasecreate/</link>
		<comments>http://sikachu.com/2010/08/possible-pitfall-on-activerecordbasecreate/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 16:32:44 +0000</pubDate>
		<dc:creator>Sikachu!</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[active_record]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Rails 3]]></category>

		<guid isPermaLink="false">http://sikachu.com/?p=722</guid>
		<description><![CDATA[I came across this a while ago when I was trying to clean up my code. Just write it down so you won&#8217;t follow me Consider that Post having :title attribute and class Post &#60; ActiveRecord::Base validates_presence_of :title end Well, what do you think would be the result of the following expression? if Post.create&#40;:title =&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>I came across this a while ago when I was trying to clean up my code. Just write it down so you won&#8217;t follow me <img src='http://sikachu.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Consider that <code>Post</code> having <code>:title</code> attribute and</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Post <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  validates_presence_of <span style="color:#ff3333; font-weight:bold;">:title</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Well, what do you think would be the result of the following expression?</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">if</span> Post.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</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;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Saved!&quot;</span>
<span style="color:#9966CC; font-weight:bold;">else</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Validation error ...&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Somehow, I expected <code>"Validation error ..."</code> message from it, but I got <code>"Saved!"</code> Why?</p>
<h3>Return value of <code>#create</code></h3>
<p>You need to remember that <code>#create</code> method always return the object itself, which have the <code>id</code> as <code>nil</code>. This, evaluates to <code>true</code> and make our code fail. The solution for this problem would be using <code>#new</code> to create object, and then using <code>#save</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">post = Post.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</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;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">if</span> post.<span style="color:#9900CC;">save</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Saved!&quot;</span>
<span style="color:#9966CC; font-weight:bold;">else</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Validation error ...&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>For you one-liner, I think you can do this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">if</span> post = Post.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</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;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> post.<span style="color:#9900CC;">save</span></pre></div></div>

<p>or (as suggested by <a href="http://twitter.com/shr/status/21801270429" target="_blank">shr</a>)</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">if</span> Post.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</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;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">save</span></pre></div></div>

<img src="http://feeds.feedburner.com/~r/SikachuBlog/~4/_374Snhz8S4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sikachu.com/2010/08/possible-pitfall-on-activerecordbasecreate/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

