<?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>ไอเอินบล๊อก &#187; Rails</title>
	<atom:link href="http://www.iearn.in.th/tag/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.iearn.in.th</link>
	<description>Just Play and Just Knowledge</description>
	<lastBuildDate>Fri, 05 Aug 2011 15:10:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Installing Imagemagick and rmagick on Ubuntu</title>
		<link>http://www.iearn.in.th/2010/11/20/installing-imagemagick-and-rmagick-on-ubuntu/</link>
		<comments>http://www.iearn.in.th/2010/11/20/installing-imagemagick-and-rmagick-on-ubuntu/#comments</comments>
		<pubDate>Sat, 20 Nov 2010 04:50:38 +0000</pubDate>
		<dc:creator>nolifelover</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[RoR]]></category>
		<category><![CDATA[Imagemagick]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[rmagick]]></category>

		<guid isPermaLink="false">http://www.iearn.in.th/?p=656</guid>
		<description><![CDATA[ง่ายๆ แค่ 2 ขั้นตอน sudo apt-get install imagemagick libmagick9-dev sudo gem install rmagick 4 views]]></description>
			<content:encoded><![CDATA[<p>ง่ายๆ แค่ 2 ขั้นตอน<br />
<code><br />
sudo apt-get install imagemagick libmagick9-dev<br />
sudo gem install rmagick<br />
</code></p>

<p class="sayac_bilgi">4 views</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iearn.in.th/2010/11/20/installing-imagemagick-and-rmagick-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install Ruby 1.9.2 and Rails 3 on Ubuntu 10.10</title>
		<link>http://www.iearn.in.th/2010/11/19/install-ruby-1-9-2-and-rails-3-on-ubuntu-10-10/</link>
		<comments>http://www.iearn.in.th/2010/11/19/install-ruby-1-9-2-and-rails-3-on-ubuntu-10-10/#comments</comments>
		<pubDate>Fri, 19 Nov 2010 15:25:10 +0000</pubDate>
		<dc:creator>nolifelover</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[RoR]]></category>
		<category><![CDATA[E-Ruby]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.iearn.in.th/?p=652</guid>
		<description><![CDATA[ง่ายๆครับ ทำตามนี้เลย apt-get install gcc g++ build-essential libssl-dev libreadline5-dev zlib1g-dev linux-headers-generic libsqlite3-dev wget ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p0.tar.gz tar -zxvf ruby-1.9.2-p0.tar.gz cd ruby-1.9.2-p0 ./configure --prefix=/usr/local/ruby make &#038;&#038; sudo make install สุดท้ายก็แก้ไข path ให้ไปที่ /usr/local/ruby/bin gedit /etc/envitonment source /etc/environment 12 views]]></description>
			<content:encoded><![CDATA[<p>ง่ายๆครับ ทำตามนี้เลย<br />
<code>apt-get install gcc g++ build-essential libssl-dev libreadline5-dev zlib1g-dev linux-headers-generic libsqlite3-dev<br />
wget ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p0.tar.gz<br />
tar -zxvf ruby-1.9.2-p0.tar.gz<br />
cd ruby-1.9.2-p0<br />
./configure --prefix=/usr/local/ruby<br />
make &#038;&#038; sudo make install</code></p>
<p>สุดท้ายก็แก้ไข path ให้ไปที่ /usr/local/ruby/bin<br />
<code>gedit /etc/envitonment<br />
source /etc/environment</code></p>

<p class="sayac_bilgi">12 views</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iearn.in.th/2010/11/19/install-ruby-1-9-2-and-rails-3-on-ubuntu-10-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deploy rails app on a suburi</title>
		<link>http://www.iearn.in.th/2010/03/11/deploy-rails-app-on-a-suburi/</link>
		<comments>http://www.iearn.in.th/2010/03/11/deploy-rails-app-on-a-suburi/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 09:00:30 +0000</pubDate>
		<dc:creator>nolifelover</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[RoR]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[rails suburi]]></category>
		<category><![CDATA[relative url]]></category>

		<guid isPermaLink="false">http://www.iearn.in.th/?p=628</guid>
		<description><![CDATA[หากใครอยากที่จะ deploy rails สำหรับให้อยู่ในส่วนของ suburi เช่น example.com/app จำเป็นจะต้องมีการใช้งานในส่วนของการสั่งให้ rails ทราบว่าตอนนี้มันกำลังอยู่ใน url ใด ซึ่งในส่วนของการ deploy ผมได้ deploy apache+mod_proxy+mongrel ซึ่งผมจะมาเขียนที่หลังละกันครับ สำหรับการทำให้ rails deploy บน suburi ทำได้ดังนี้ครับ โดยการแก้ไขในส่วนของ environment.rb config.action_controller.relative_url_root = &#34;/rails&#34; เป็นอันว่าเรียบร้อย 17 views]]></description>
			<content:encoded><![CDATA[<p>หากใครอยากที่จะ deploy rails สำหรับให้อยู่ในส่วนของ suburi เช่น example.com/app จำเป็นจะต้องมีการใช้งานในส่วนของการสั่งให้ rails ทราบว่าตอนนี้มันกำลังอยู่ใน url ใด ซึ่งในส่วนของการ deploy ผมได้ deploy apache+mod_proxy+mongrel ซึ่งผมจะมาเขียนที่หลังละกันครับ<br />
สำหรับการทำให้ rails deploy บน suburi ทำได้ดังนี้ครับ โดยการแก้ไขในส่วนของ environment.rb</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;">config.<span style="color:#9900CC;">action_controller</span>.<span style="color:#9900CC;">relative_url_root</span> = <span style="color:#996600;">&quot;/rails&quot;</span></pre></div></div>

<p>เป็นอันว่าเรียบร้อย</p>

<p class="sayac_bilgi">17 views</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iearn.in.th/2010/03/11/deploy-rails-app-on-a-suburi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>จะอ่าน Rails Api ได้จากไหน?</title>
		<link>http://www.iearn.in.th/2009/05/29/%e0%b8%88%e0%b8%b0%e0%b8%ad%e0%b9%88%e0%b8%b2%e0%b8%99-rails-api-%e0%b9%84%e0%b8%94%e0%b9%89%e0%b8%88%e0%b8%b2%e0%b8%81%e0%b9%84%e0%b8%ab%e0%b8%99/</link>
		<comments>http://www.iearn.in.th/2009/05/29/%e0%b8%88%e0%b8%b0%e0%b8%ad%e0%b9%88%e0%b8%b2%e0%b8%99-rails-api-%e0%b9%84%e0%b8%94%e0%b9%89%e0%b8%88%e0%b8%b2%e0%b8%81%e0%b9%84%e0%b8%ab%e0%b8%99/#comments</comments>
		<pubDate>Fri, 29 May 2009 06:11:36 +0000</pubDate>
		<dc:creator>nolifelover</dc:creator>
				<category><![CDATA[RoR]]></category>
		<category><![CDATA[basic rails]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[rails api]]></category>
		<category><![CDATA[rails class]]></category>
		<category><![CDATA[rails doc]]></category>
		<category><![CDATA[rails method]]></category>
		<category><![CDATA[rails tutorails]]></category>
		<category><![CDATA[start with rails]]></category>

		<guid isPermaLink="false">http://www.iearn.in.th/?p=536</guid>
		<description><![CDATA[สำหรับหลายคนที่ต้องการนำเอา Rails Api มาใช้เพื่อค้นหา method ต่างๆ รวมถึงเพื่อที่จะอ่านตัวอย่างในส่วนของ example ของโค้ดที่เขาได้เขียนไว้ให้ดู หลายคนอาจจะต้องเปิดเน็ตเพื่ออ่าน และปัยหาอยุ่ที่ว่าถ้าเน็ตช้าเราจะทำไง มันก็ช้าครับวันนี้ผมได้เจอ http://www.railsbrain.com/ ซึ่งได้รวบเอา api ทั้งหมดมา zip จากนั้นก็แจกจ่ายครับโดยผมได้โหลดมาเก็บไว้แล้วหากใครสนใจโหลดต่อได้เลย * Rails v2.3.2 Docs view online download * Rails v2.2.2 Docs view online download * Rails v2.1.2 Docs view online download * Rails v2.1.0 Docs view online download * Rails v2.0.5 Docs view online download * Rails [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.iearn.in.th/wp-content/uploads/2009/05/rails-api.jpg"><img src="http://www.iearn.in.th/wp-content/uploads/2009/05/rails-api-300x209.jpg" alt="rails-api" title="rails-api" width="300" height="209" class="aligncenter size-medium wp-image-537" /></a></p>
<p>สำหรับหลายคนที่ต้องการนำเอา Rails Api มาใช้เพื่อค้นหา method ต่างๆ รวมถึงเพื่อที่จะอ่านตัวอย่างในส่วนของ example ของโค้ดที่เขาได้เขียนไว้ให้ดู หลายคนอาจจะต้องเปิดเน็ตเพื่ออ่าน และปัยหาอยุ่ที่ว่าถ้าเน็ตช้าเราจะทำไง มันก็ช้าครับวันนี้ผมได้เจอ<a href="http://www.railsbrain.com/"> http://www.railsbrain.com/</a> ซึ่งได้รวบเอา api ทั้งหมดมา zip จากนั้นก็แจกจ่ายครับโดยผมได้โหลดมาเก็บไว้แล้วหากใครสนใจโหลดต่อได้เลย<br />
<span id="more-536"></span><br />
    * Rails v2.3.2 Docs <a href="http://www.iearn.in.th/api/rails-2.3.2/">view online</a>  <a href="http://www.iearn.in.th/api/railsbrain_rails-2.3.2.zip">download</a><br />
    * Rails v2.2.2 Docs <a href="http://www.iearn.in.th/api/rails-2.2.2/">view online</a>  <a href="http://www.iearn.in.th/api/railsbrain_rails-2.2.2.zip">download</a><br />
    * Rails v2.1.2 Docs <a href="http://www.iearn.in.th/api/rails-2.1.2/">view online</a>  <a href="http://www.iearn.in.th/api/railsbrain_rails-2.1.2.zip">download</a><br />
    * Rails v2.1.0 Docs <a href="http://www.iearn.in.th/api/rails-2.1.0/">view online</a>  <a href="http://www.iearn.in.th/api/railsbrain_rails-2.1.0.zip">download</a><br />
    * Rails v2.0.5 Docs <a href="http://www.iearn.in.th/api/rails-2.0.5/">view online</a>  <a href="http://www.iearn.in.th/api/railsbrain_rails-2.0.5.zip">download</a><br />
    * Rails v2.0.2 Docs <a href="http://www.iearn.in.th/api/rails-2.0.2/">view online</a>  <a href="http://www.iearn.in.th/api/railsbrain_rails-2.0.2.zip">download</a><br />
    * Rails v1.2.6 Docs <a href="http://www.iearn.in.th/api/rails-1.2.6/">view online</a>  <a href="http://www.iearn.in.th/api/railsbrain_rails-1.2.6.zip">download</a><br />
    * Rails v1.2.5 Docs <a href="http://www.iearn.in.th/api/rails-1.2.5/">view online</a>  <a href="http://www.iearn.in.th/api/railsbrain_rails-1.2.5.zip">download</a><br />
    * Rails v1.2.4 Docs <a href="http://www.iearn.in.th/api/rails-1.2.4/">view online</a>  <a href="http://www.iearn.in.th/api/railsbrain_rails-1.2.4.zip">download</a><br />
    * Rails v1.2.3 Docs <a href="http://www.iearn.in.th/api/rails-1.2.3/">view online</a>  <a href="http://www.iearn.in.th/api/railsbrain_rails-1.2.3.zip">download</a><br />
    * Rails v1.2.2 Docs <a href="http://www.iearn.in.th/api/rails-1.2.2/">view online</a>  <a href="http://www.iearn.in.th/api/railsbrain_rails-1.2.2.zip">download</a><br />
    * Rails v1.2.1 Docs <a href="http://www.iearn.in.th/api/rails-1.2.1/">view online</a>  <a href="http://www.iearn.in.th/api/railsbrain_rails-1.2.1.zip">download</a><br />
    * Rails v1.2.0 Docs <a href="http://www.iearn.in.th/api/rails-1.2.0/">view online</a>  <a href="http://www.iearn.in.th/api/railsbrain_rails-1.2.0.zip">download</a><br />
    * Rails v1.1.6 Docs <a href="http://www.iearn.in.th/api/rails-1.1.6/">view online</a>  <a href="http://www.iearn.in.th/api/railsbrain_rails-1.1.6.zip">download</a></p>
<p>ท่านสามารถดาวโหลดได้เลยครับ ขอบคุณ <a href="http://www.railsbrain.com/"> http://www.railsbrain.com/</a>  อย่างแรง</p>

<p class="sayac_bilgi">18 views</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iearn.in.th/2009/05/29/%e0%b8%88%e0%b8%b0%e0%b8%ad%e0%b9%88%e0%b8%b2%e0%b8%99-rails-api-%e0%b9%84%e0%b8%94%e0%b9%89%e0%b8%88%e0%b8%b2%e0%b8%81%e0%b9%84%e0%b8%ab%e0%b8%99/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>เริ่มต้น Rail ง่ายๆด้วย Bort</title>
		<link>http://www.iearn.in.th/2009/05/25/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b8%95%e0%b9%89%e0%b8%99-rail-%e0%b8%87%e0%b9%88%e0%b8%b2%e0%b8%a2%e0%b9%86%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-bort/</link>
		<comments>http://www.iearn.in.th/2009/05/25/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b8%95%e0%b9%89%e0%b8%99-rail-%e0%b8%87%e0%b9%88%e0%b8%b2%e0%b8%a2%e0%b9%86%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-bort/#comments</comments>
		<pubDate>Sun, 24 May 2009 22:26:30 +0000</pubDate>
		<dc:creator>nolifelover</dc:creator>
				<category><![CDATA[RoR]]></category>
		<category><![CDATA[base rails]]></category>
		<category><![CDATA[basic rails]]></category>
		<category><![CDATA[bort]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[rails tutorails]]></category>
		<category><![CDATA[start with rails]]></category>

		<guid isPermaLink="false">http://www.iearn.in.th/?p=528</guid>
		<description><![CDATA[กำลังตามหาโปรแจคนี้อยุ่พอดีหลัวจากที่เห็นแว๊บๆ แต่ว่าจำไม่ได้ว่ามันอยู่เว็บไหน 55 พยายามค้นหาตาม google ประมาณเกือบชมได้ครับ ไปเจอเอาที่  http://www.rails66.com/blog/?p=89 ซึ่งเป็นอันว่าจบการค้นหาครับ แต่ยังไงก็เอามาไว้ในเว็บด้วยละกันสำหรับการลงได้ 2 วิธีครับหากว่ามี git ก็ clone มาแต่หากว่าไม่มีสามารถดาวโหลดธรรมาเป็น zip file มาได้ครับ สำหรับสิ่งที่เจ้า Bort มีให้แล้วคือ RESTful Authentication User Roles Open ID Authentication Will Paginate Rspec &#38; Rspec-rails Exception Notifier Asset Packager บอกได้เลยว่าหากคุณทำ app ธรรมดาทุกตัวจำเป็นต้องมีระบบพวกนี้ครับ หากท่านสนใจตรงไปที่นี้เลยครับ http://github.com/fudgestudios/bort/tree/master 28 views]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.iearn.in.th/wp-content/uploads/2009/05/bort-a-base-rails-apllication.jpg"><img class="aligncenter size-medium wp-image-529" title="bort-a-base-rails-apllication" src="http://www.iearn.in.th/wp-content/uploads/2009/05/bort-a-base-rails-apllication-300x107.jpg" alt="bort-a-base-rails-apllication" width="300" height="107" /></a></p>
<p>กำลังตามหาโปรแจคนี้อยุ่พอดีหลัวจากที่เห็นแว๊บๆ แต่ว่าจำไม่ได้ว่ามันอยู่เว็บไหน 55 พยายามค้นหาตาม google ประมาณเกือบชมได้ครับ ไปเจอเอาที่ <a href="http://www.rails66.com/blog/?p=89"> http://www.rails66.com/blog/?p=89</a> ซึ่งเป็นอันว่าจบการค้นหาครับ แต่ยังไงก็เอามาไว้ในเว็บด้วยละกัน<span id="more-528"></span>สำหรับการลงได้ 2 วิธีครับหากว่ามี git ก็ clone มาแต่หากว่าไม่มีสามารถดาวโหลดธรรมาเป็น zip file มาได้ครับ สำหรับสิ่งที่เจ้า Bort มีให้แล้วคือ</p>
<p style="padding-left: 30px;">
RESTful Authentication<br />
User Roles<br />
Open ID Authentication<br />
Will Paginate<br />
Rspec &amp; Rspec-rails<br />
Exception Notifier<br />
Asset Packager</p>
<p>บอกได้เลยว่าหากคุณทำ app ธรรมดาทุกตัวจำเป็นต้องมีระบบพวกนี้ครับ หากท่านสนใจตรงไปที่นี้เลยครับ <a href="http://github.com/fudgestudios/bort/tree/master">http://github.com/fudgestudios/bort/tree/master</a></p>

<p class="sayac_bilgi">28 views</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iearn.in.th/2009/05/25/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b8%95%e0%b9%89%e0%b8%99-rail-%e0%b8%87%e0%b9%88%e0%b8%b2%e0%b8%a2%e0%b9%86%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-bort/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>make text field with auto complete in rails</title>
		<link>http://www.iearn.in.th/2009/05/24/make-text-field-with-auto-complete-in-rails/</link>
		<comments>http://www.iearn.in.th/2009/05/24/make-text-field-with-auto-complete-in-rails/#comments</comments>
		<pubDate>Sat, 23 May 2009 17:16:28 +0000</pubDate>
		<dc:creator>nolifelover</dc:creator>
				<category><![CDATA[RoR]]></category>
		<category><![CDATA[auto complete]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[rails muti lang]]></category>
		<category><![CDATA[rails plugins]]></category>
		<category><![CDATA[rails tutorails]]></category>
		<category><![CDATA[start with rails]]></category>
		<category><![CDATA[text field with auto complete]]></category>

		<guid isPermaLink="false">http://www.iearn.in.th/?p=507</guid>
		<description><![CDATA[ที่จริงช่วงนี้ทำโปรแจคเกี่ยวกัน ruby on rails เยอะมากๆ บอกได้ว่าหมกหมุ่นเลยละเลยได้เอาอะไรที่ลองและนำเอาไปใช้ในโปรแจคจริงๆ มาถ่ายทอดสู่ผู้ที่กำลังสนใจอยู่โดยหวังให้ท่านเป็นผู้พัฒนาเว็บด้วย ruby on rails เหมือนกัน สำหรับวันนี้มาแนะนำการใช้ text field with auto complete ซึ่งเป็น plugins สำหรับอะไรดูตามชื่อคงจะรู้อยู่นะครับ โดยชื่อ plugins คือ rails-auto_complete โดยหากใครต้องการเขียนตรงไปตรงมาตาม plugins ของเขาก็สามารถอ่านเอาได้ทั่วไปครับส่วนของผมเอาเป็นว่าไม่ใช้แบบเขาต้องการละกันเนื่องจากสิ่งที่ต้องการแตกต่างออกไปนิดหน่อย เริ่มต้นด้วยการโหลด plugins มาก่อนเลยครับ http://github.com/rails/auto_complete/tree/master เมื่อโหลดมาแล้วลองเล่นดูครับหากว่าต้องการแบบที่ผมอธิบายลองมาดูครับ 1 &#60;%= text_field_with_auto_complete :txaction, :customer_code, &#123; :size =&#62; 15 &#125;, &#123; :url =&#62; formatted_findjs_customers_path&#40;:js&#41;, :method =&#62; :get, :with=&#62;&#34;'code='+element.value&#34; &#125; %&#62; สำหรับโค้ดตัวนี้เป็นการเรียก action=> ajax_customer_info [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.iearn.in.th/wp-content/uploads/2009/05/text_field_with_auto_complete.jpg"><img class="aligncenter size-medium wp-image-508" title="text_field_with_auto_complete" src="http://www.iearn.in.th/wp-content/uploads/2009/05/text_field_with_auto_complete-300x55.jpg" alt="text_field_with_auto_complete" width="300" height="55" /></a></p>
<p>ที่จริงช่วงนี้ทำโปรแจคเกี่ยวกัน ruby on rails เยอะมากๆ บอกได้ว่าหมกหมุ่นเลยละเลยได้เอาอะไรที่ลองและนำเอาไปใช้ในโปรแจคจริงๆ มาถ่ายทอดสู่ผู้ที่กำลังสนใจอยู่โดยหวังให้ท่านเป็นผู้พัฒนาเว็บด้วย ruby on rails เหมือนกัน สำหรับวันนี้มาแนะนำการใช้ text field with auto complete ซึ่งเป็น plugins สำหรับอะไรดูตามชื่อคงจะรู้อยู่นะครับ<span id="more-507"></span><br />
โดยชื่อ plugins คือ rails-auto_complete โดยหากใครต้องการเขียนตรงไปตรงมาตาม plugins ของเขาก็สามารถอ่านเอาได้ทั่วไปครับส่วนของผมเอาเป็นว่าไม่ใช้แบบเขาต้องการละกันเนื่องจากสิ่งที่ต้องการแตกต่างออกไปนิดหน่อย เริ่มต้นด้วยการโหลด plugins มาก่อนเลยครับ <a href="http://github.com/rails/auto_complete/tree/master">http://github.com/rails/auto_complete/tree/master</a> เมื่อโหลดมาแล้วลองเล่นดูครับหากว่าต้องการแบบที่ผมอธิบายลองมาดูครับ</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>= text_field_with_auto_complete <span style="color:#ff3333; font-weight:bold;">:txaction</span>, <span style="color:#ff3333; font-weight:bold;">:customer_code</span>, <span style="color:#006600; font-weight:bold;">&#123;</span> :<span style="color:#5A0A0A; font-weight:bold;">size</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">15</span> <span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> formatted_findjs_customers_path<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:js</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#ff3333; font-weight:bold;">:method</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:get</span>, <span style="color:#ff3333; font-weight:bold;">:with</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">&quot;'code='+element.value&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></td></tr></table></div>

<p>สำหรับโค้ดตัวนี้เป็นการเรียก action=> ajax_customer_info สำหรับการประมวลผลครับ และส่ง parameter คือค่าใน field txaction_customer_code ครับ โดยกำหนดตรง :with=>&#8221;&#8216;code=&#8217;+element.value&#8221; ส่วนถัดไปอยู่ใน controller ครับ</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> findjs
    <span style="color:#0066ff; font-weight:bold;">@customer</span> = Customer.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:all</span>, <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'code LIKE ?'</span>, <span style="color:#996600;">&quot;%#{params[:code]}%&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:code</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>จะเป็นการค้นหารหัสลูกค้านั้นทั้งหมดไปโชว์ใน field customer_code ครับ</p>
<p><a href="http://www.iearn.in.th/wp-content/uploads/2009/05/text_field_with_auto_complete-demo1.jpg"><img src="http://www.iearn.in.th/wp-content/uploads/2009/05/text_field_with_auto_complete-demo1-300x102.jpg" alt="text_field_with_auto_complete-demo1" title="text_field_with_auto_complete-demo1" width="300" height="102" class="aligncenter size-medium wp-image-510" /></a></p>

<p class="sayac_bilgi">37 views</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iearn.in.th/2009/05/24/make-text-field-with-auto-complete-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use I18N with Label</title>
		<link>http://www.iearn.in.th/2009/05/23/use-i18n-with-label/</link>
		<comments>http://www.iearn.in.th/2009/05/23/use-i18n-with-label/#comments</comments>
		<pubDate>Sat, 23 May 2009 16:49:56 +0000</pubDate>
		<dc:creator>nolifelover</dc:creator>
				<category><![CDATA[RoR]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[internationalization on rails]]></category>
		<category><![CDATA[label]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[rails muti lang]]></category>
		<category><![CDATA[rails tutorails]]></category>
		<category><![CDATA[start with rails]]></category>

		<guid isPermaLink="false">http://www.iearn.in.th/?p=501</guid>
		<description><![CDATA[ช่วงนี้เขียนเรื่อง i18n บ่อยเลยเอา plugins ที่ช่วยให้การทำงานกับ i18n ง่ายขึ้นเมื่อเราใช้ label สำหรับการแสดงชื่อ column ในฐานข้อมูลทำให้เมื่อ gennerate scaffold มาเราไม่จำเป็นต้องแก้อะไร หากเราได้ทำการแปลโมเดลโดยการใช้ i18n core ของ ror ไว้แล้วสามารถที่ใช้งานได้เลย plugins ที่นำเสนอชื่อว่า i18n_label ครับเมื่อเราลง plugins ตัวนี้แล้วจะทำให้ view ทำการเรียกการแปลโมเดลนั้นให้เองเลยอะ สำหรับหากว่าใครต้องการรายละเอียดอื่นๆ สามารถดูได้ที่ http://github.com/iain/i18n_label/tree/master สำหรับการใช้งานเราสามารถใช้งาน label ธรรมดาได้เลยครับ &#38;lt;% form_for&#40;@txaction&#41; do &#124;f&#124; %&#38;gt; &#38;lt;%= f.error_messages %&#38;gt; &#38;lt;%= f.label :code %&#38;gt; &#38;lt;== ส่วนนี้จะแสดงเป็น ชื่อที่ถูกแปลของโมเดลครับ &#38;lt;%= f.text_field :code %&#38;gt; &#38;lt;%= f.label [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.iearn.in.th/wp-content/uploads/2009/05/i18n-label.jpg"><img class="aligncenter size-medium wp-image-502" title="i18n-label" src="http://www.iearn.in.th/wp-content/uploads/2009/05/i18n-label-300x64.jpg" alt="i18n-label" width="300" height="64" /></a><br />
ช่วงนี้เขียนเรื่อง i18n บ่อยเลยเอา plugins ที่ช่วยให้การทำงานกับ i18n ง่ายขึ้นเมื่อเราใช้ label สำหรับการแสดงชื่อ column ในฐานข้อมูลทำให้เมื่อ gennerate scaffold มาเราไม่จำเป็นต้องแก้อะไร หากเราได้ทำการแปลโมเดลโดยการใช้ i18n core ของ ror ไว้แล้วสามารถที่ใช้งานได้เลย<span id="more-501"></span><br />
plugins ที่นำเสนอชื่อว่า i18n_label ครับเมื่อเราลง plugins ตัวนี้แล้วจะทำให้ view ทำการเรียกการแปลโมเดลนั้นให้เองเลยอะ สำหรับหากว่าใครต้องการรายละเอียดอื่นๆ สามารถดูได้ที่ <a href="http://github.com/iain/i18n_label/tree/master">http://github.com/iain/i18n_label/tree/master</a> สำหรับการใช้งานเราสามารถใช้งาน label ธรรมดาได้เลยครับ</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&amp;</span>lt;<span style="color:#006600; font-weight:bold;">%</span> <span style="color:#5A0A0A; font-weight:bold;">form_for</span><span style="color:#006600; font-weight:bold;">&#40;</span>@txaction<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">%&amp;</span>gt;
    <span style="color:#006600; font-weight:bold;">&amp;</span>lt;<span style="color:#006600; font-weight:bold;">%</span>= f.<span style="color:#9900CC;">error_messages</span> <span style="color:#006600; font-weight:bold;">%&amp;</span>gt;
    <span style="color:#006600; font-weight:bold;">&amp;</span>lt;<span style="color:#006600; font-weight:bold;">%</span>= f.<span style="color:#9900CC;">label</span> <span style="color:#ff3333; font-weight:bold;">:code</span> <span style="color:#006600; font-weight:bold;">%&amp;</span>gt; <span style="color:#006600; font-weight:bold;">&amp;</span>lt;== ส่วนนี้จะแสดงเป็น ชื่อที่ถูกแปลของโมเดลครับ
    <span style="color:#006600; font-weight:bold;">&amp;</span>lt;<span style="color:#006600; font-weight:bold;">%</span>= f.<span style="color:#9900CC;">text_field</span> <span style="color:#ff3333; font-weight:bold;">:code</span> <span style="color:#006600; font-weight:bold;">%&amp;</span>gt;
    <span style="color:#006600; font-weight:bold;">&amp;</span>lt;<span style="color:#006600; font-weight:bold;">%</span>= f.<span style="color:#9900CC;">label</span> <span style="color:#ff3333; font-weight:bold;">:customer_code</span> <span style="color:#006600; font-weight:bold;">%&amp;</span>gt;</pre></div></div>

<p>ส่วนโค้ดด้านล่างคือตัวอย่างของการแปล active record ครับ</p>

<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;">th:
  activerecord:
    txaction: การทำรายการ
    attributes:
      txaction:
        code: รหัส
        customer_code: รหัสลูกค้า</pre></div></div>


<p class="sayac_bilgi">7 views</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iearn.in.th/2009/05/23/use-i18n-with-label/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails ActiveRecord Internationalization with I18n</title>
		<link>http://www.iearn.in.th/2009/05/20/rails-activerecord-internationalization-with-i18n/</link>
		<comments>http://www.iearn.in.th/2009/05/20/rails-activerecord-internationalization-with-i18n/#comments</comments>
		<pubDate>Tue, 19 May 2009 22:38:08 +0000</pubDate>
		<dc:creator>nolifelover</dc:creator>
				<category><![CDATA[RoR]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[internationalization on rails]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[rails muti lang]]></category>
		<category><![CDATA[rails tutorails]]></category>
		<category><![CDATA[start with rails]]></category>

		<guid isPermaLink="false">http://www.iearn.in.th/?p=490</guid>
		<description><![CDATA[หลังจากที่เมื่อวานได้มาเขียนเรื่องการทำ muti lang ในส่วนของหน้าเว็บไปแล้วในส่วต่อไปจะเป็นการแก้ให้ model ของเราสามารถแสดง error เป็นภาษาไทยได้ โดยลักษณะการทำนั้นเหมือนกันการทำในส่วนของการทำ muti lang ในส่วนของ view โดยเราสามารแปลโมเดลได้เลยครับ โดยที่ไม่ต้องไปแปลในตัวของ model โดยการใช้ method human แล้ว model.th.yml 1 2 3 4 5 6 7 8 9 th: activerecord: models: account: ผู้ใช้งาน bill_history: ประวัติการออกบิล bill: รายการบิล branch_config: รายการการตั้งค่า branch: สาขา credit: รายการเครดิต โดยในส่วนของ th: บอกให้รู้ว่าเป็นภาษาไทยครับ models: จะเป็นส่วนของการแปลชื่อโมเดลทั้งหมดครับ ในส่วนของการแปล attribute ของแต่ละโมเดลให้เพิ่มต่อไปด้านล่างครับ 1 2 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.iearn.in.th/wp-content/uploads/2009/05/rails-inter-activerecord.jpg"><img src="http://www.iearn.in.th/wp-content/uploads/2009/05/rails-inter-activerecord-300x160.jpg" alt="rails-inter-activerecord" title="rails-inter-activerecord" width="300" height="160" class="aligncenter size-medium wp-image-491" /></a><br />
หลังจากที่เมื่อวานได้มาเขียนเรื่องการทำ muti lang ในส่วนของหน้าเว็บไปแล้วในส่วต่อไปจะเป็นการแก้ให้ model ของเราสามารถแสดง error เป็นภาษาไทยได้ โดยลักษณะการทำนั้นเหมือนกันการทำในส่วนของการทำ muti lang ในส่วนของ view โดยเราสามารแปลโมเดลได้เลยครับ โดยที่ไม่ต้องไปแปลในตัวของ model โดยการใช้ method human แล้ว<br />
<span id="more-490"></span><br />
<code>model.th.yml</code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="rails" style="font-family:monospace;">th:
  activerecord:
    models:
      account: ผู้ใช้งาน
      bill_history: ประวัติการออกบิล
      bill: รายการบิล
      branch_config: รายการการตั้งค่า
      branch: สาขา
      credit: รายการเครดิต</pre></td></tr></table></div>

<p>โดยในส่วนของ<br />
th: บอกให้รู้ว่าเป็นภาษาไทยครับ<br />
models: จะเป็นส่วนของการแปลชื่อโมเดลทั้งหมดครับ<br />
ในส่วนของการแปล attribute ของแต่ละโมเดลให้เพิ่มต่อไปด้านล่างครับ</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="rails" style="font-family:monospace;">     attributes:
        account:
          username: ชื่อผู้ใช้งาน
          display_name: ชื่อแสดง
          password: รหัสผ่าน
          password_confirmation: ยืนยันรหัสผ่าน
        bill_history:
          bill_id: หมายเลขบิล
          on_date: วันที่</pre></td></tr></table></div>

<p>โดย ในส่วนของ account: จะเป็นการแปลชื่อ attribute ของตารางเราครับ<br />
สำหรับการแปลในส่วนของข้อความ error ต่างๆ สามารถทำการแปลเหมือนกันครับแต่เพื่อความรวดเร็วคงต้องแนะนำที่มีการแปลให้แล้วครับ โดยเป็นการแปลทั้งเวลา สกุลเงิน รวมถึง error ในส่วนของ active record ให้แล้วครับ โดยหากท่านต้องการภาษาอื่นให้ลองหาใน <a href="http://github.com/svenfuchs/rails-i18n/tree/master/rails">http://github.com/svenfuchs/rails-i18n/tree/master/rails</a> แต่สำหรับภาษาไทยผมโหลดมาใช้แล้วครับ <a href="http://www.iearn.in.th/wp-download/th.rb">th.rb</a>  โดยโครงสร้างไม่ได้เขียนเป็น yml นะครับ</p>
<p><a href="http://www.iearn.in.th/wp-content/uploads/2009/05/rails-inter-activerecord-test.jpg"><img src="http://www.iearn.in.th/wp-content/uploads/2009/05/rails-inter-activerecord-test-300x84.jpg" alt="rails-inter-activerecord-test" title="rails-inter-activerecord-test" width="300" height="84" class="aligncenter size-medium wp-image-492" /></a></p>

<p class="sayac_bilgi">22 views</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iearn.in.th/2009/05/20/rails-activerecord-internationalization-with-i18n/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Muti Internationalization (I18N)</title>
		<link>http://www.iearn.in.th/2009/05/19/rails-muti-internationalization-i18n/</link>
		<comments>http://www.iearn.in.th/2009/05/19/rails-muti-internationalization-i18n/#comments</comments>
		<pubDate>Mon, 18 May 2009 21:37:54 +0000</pubDate>
		<dc:creator>nolifelover</dc:creator>
				<category><![CDATA[RoR]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[rails tutorails]]></category>
		<category><![CDATA[start with rails]]></category>

		<guid isPermaLink="false">http://www.iearn.in.th/?p=477</guid>
		<description><![CDATA[สำหรับหลายท่านคงอยากทำให้ rails สามารถทำ muti lang ได้ซึ่งใน version ก่อน 2.2 ไม่มี api core สำหรับการทำ Internationalization แต่ตั้งแต่ 2.2 เป็นต้นไปทัมพัฒนาได้ใส่ i18n core สำหรับการใช้งานแบบ muti lang โดยผมก้ได้เปลี่ยนวิธีใช้จาก gettext มาเป็น i18n ตาม core ของ rails แล้วโดยงานที่ผมทำไม่ได้เกี่ยวอะไรกับการทำหลายภาษาหรอกครับแค่ว่าเอามาแปลไทยเท่านั้นเพราะเผื่อว่าลูกค้าต้องการเปลี่ยนคำจะได้ไม่ต้องไล่แก้ที่ view อยู่มันเหนื่อยเลยเอา i18n มาช่วย config/initializers/load_translations.rb 1 2 3 4 %w&#123;yml rb&#125;.each do &#124;type&#124; I18n.load_path += Dir.glob&#40;&#34;#{RAILS_ROOT}/app/locales/**/*.#{type}&#34;&#41; end I18n.default_locale = 'th' สำหรับโค้ดส่วนนี้จะเป็นส่วนที่ใช้สำหรับโหลด เจ้าตัวแปลมาครับโดยจะอยู่ใน app/locales ครับ [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.iearn.in.th/wp-content/uploads/2009/05/rails-internationalization.jpg"><img src="http://www.iearn.in.th/wp-content/uploads/2009/05/rails-internationalization-300x84.jpg" alt="rails-internationalization" title="rails-internationalization" width="300" height="84" class="aligncenter size-medium wp-image-479" /></a></p>
<p>สำหรับหลายท่านคงอยากทำให้ rails สามารถทำ muti lang ได้ซึ่งใน version ก่อน 2.2 ไม่มี api core สำหรับการทำ Internationalization แต่ตั้งแต่ 2.2 เป็นต้นไปทัมพัฒนาได้ใส่ i18n core สำหรับการใช้งานแบบ muti lang โดยผมก้ได้เปลี่ยนวิธีใช้จาก gettext มาเป็น i18n ตาม core ของ rails แล้วโดยงานที่ผมทำไม่ได้เกี่ยวอะไรกับการทำหลายภาษาหรอกครับแค่ว่าเอามาแปลไทยเท่านั้นเพราะเผื่อว่าลูกค้าต้องการเปลี่ยนคำจะได้ไม่ต้องไล่แก้ที่ view อยู่มันเหนื่อยเลยเอา i18n มาช่วย<br />
<span id="more-477"></span><br />
<code>config/initializers/load_translations.rb</code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#123;</span>yml rb<span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#5A0A0A; font-weight:bold;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>type<span style="color:#006600; font-weight:bold;">|</span>
  I18n.<span style="color:#9900CC;">load_path</span> <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">glob</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{RAILS_ROOT}/app/locales/**/*.#{type}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
I18n.<span style="color:#9900CC;">default_locale</span> = <span style="color:#996600;">'th'</span></pre></td></tr></table></div>

<p>สำหรับโค้ดส่วนนี้จะเป็นส่วนที่ใช้สำหรับโหลด เจ้าตัวแปลมาครับโดยจะอยู่ใน app/locales ครับ</p>
<p>ต่อไปก็มาถึงการใช้งานกันแล้วครับ สมมุคิดว่าผมมี controller ชื่อว่า hello_world_controller.rb อยู่ละครับ และมี index.html.erb<br />
<code>index.html.erb</code></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>=<span style="color:#996600;">&quot;hello_world&quot;</span><span style="color:#006600; font-weight:bold;">&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;%</span>=<span style="color:#996600;">&quot;To Day=&gt;&quot;</span><span style="color:#006600; font-weight:bold;">+</span><span style="color:#CC00FF; font-weight:bold;">Data</span>.<span style="color:#9900CC;">today</span>.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&gt;</span></pre></div></div>

<p>ผมต้องการแปล hello_world และ To day ให้เป็นภาษาไทยครับผมต้องแก้เจ้า index.html.erb ตามนี้ครับ<br />
<code>index.html.erb</code></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>=t<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;hello_world.say_hello&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;%</span>=t<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;to_day&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">+</span><span style="color:#CC00FF; font-weight:bold;">Data</span>.<span style="color:#9900CC;">today</span>.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&gt;</span></pre></div></div>

<p>เมื่อผมแก้เสร็จก็ไปทำการแก้ไขไฟล์แปลภาษากันครับ โดยในไฟล์แปลภาษาผมจะตั้งชื่อว่าอะไรก็ได้ครับขึ้นกับความพอใจครับโดยผมขอตั้งฃื่อว่า th.yml โดยผมจะเขียนโดยใช้โครงสร้าง yml ครับ<br />
<code>app/locales/th.yml</code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">th:
  <span style="color:#ff3333; font-weight:bold;">:hello_world</span>
    <span style="color:#ff3333; font-weight:bold;">:say_hello</span> สวัสดีครับ
  <span style="color:#ff3333; font-weight:bold;">:to_day</span> วันนี้วันที่</pre></td></tr></table></div>

<p>ตรงนี้สังเกตให้ดันะครับว่า :say_hello จะย่อยเข้าไปของ :hello_world เวลาใช้จึงเป็น hellow_world.say_hello ครับ ส่วน :to_day ใช้เป็น to_day ได้เลยเนื่องจากว่าไม่ได้ย่อยเข้าไปครับ และหากว่าเรียก hello_world.say_hello.morning ต้องเขียนแบบนี้ครับ</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">th:
  <span style="color:#ff3333; font-weight:bold;">:hello_world</span>
    <span style="color:#ff3333; font-weight:bold;">:say_hello</span> สวัสดีครับ
      <span style="color:#ff3333; font-weight:bold;">:morning</span> สวัสดีตอนเช้า
  <span style="color:#ff3333; font-weight:bold;">:to_day</span> วันนี้วันที่</pre></td></tr></table></div>

<p>คงไม่ยากนะครับ</p>

<p class="sayac_bilgi">20 views</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iearn.in.th/2009/05/19/rails-muti-internationalization-i18n/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Number format in Rails</title>
		<link>http://www.iearn.in.th/2009/05/17/number-format-in-rails/</link>
		<comments>http://www.iearn.in.th/2009/05/17/number-format-in-rails/#comments</comments>
		<pubDate>Sun, 17 May 2009 09:28:49 +0000</pubDate>
		<dc:creator>nolifelover</dc:creator>
				<category><![CDATA[RoR]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[rails plugins]]></category>
		<category><![CDATA[rails tutorails]]></category>
		<category><![CDATA[sprintf]]></category>
		<category><![CDATA[start with rails]]></category>

		<guid isPermaLink="false">http://www.iearn.in.th/?p=470</guid>
		<description><![CDATA[วันนี้เอาทริปอาจจะไม่เด็ดเท่าไรเพราะ programmer ทั่วไปคงรู้กันแล้ว แต่สำหรับมือใหม่คงต้องใช่ครับ สำหรับใครที่ต้องการจะแสดงผลเป็น 0001 แต่มีตัวเลขแค่ 1 เราสามารถใช้งาน rails sprintf ซึ่งมีให้ใช้งานอยู่แล้ว 1 2 &#160; sprintf&#40;'%04i', 1&#41; #result 0001 แล้วถ้าเกิดผมต้องการใช้ตัวเลขมี prefix และ auto generate อัตโนมัติเมื่อสร้างขึ้นมาจะทำอย่างไรลองมาดูกันครับ สำหรับเลขชุดที่ผมต้องการตอ้งขึ้นต้นด้วย TX01H และมีลำดับตามเป็นเลข 4 ตัวเรียกกันไปครับคือ 0001&#8230; มาดูโค้ดกันครับ 1 2 3 4 &#160; @last_txaction = Txaction.find&#40;:first,:conditions=&#62;&#91;&#34;code like ?&#34;,&#34;TX01H%&#34;&#93;,:order =&#62; &#34;code desc&#34;&#41; #find last code result =&#62;TX01Hxxxx code = @last_txaction ? @last_txaction.code.gsub&#40;&#34;TX01H&#34;,&#34;&#34;&#41;.to_i+1:1 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.iearn.in.th/wp-content/uploads/2009/05/rails-number-format.jpg"><img src="http://www.iearn.in.th/wp-content/uploads/2009/05/rails-number-format-300x118.jpg" alt="rails-number-format" title="rails-number-format" width="300" height="118" class="aligncenter size-medium wp-image-471" /></a></p>
<p>วันนี้เอาทริปอาจจะไม่เด็ดเท่าไรเพราะ programmer ทั่วไปคงรู้กันแล้ว แต่สำหรับมือใหม่คงต้องใช่ครับ สำหรับใครที่ต้องการจะแสดงผลเป็น 0001 แต่มีตัวเลขแค่ 1 เราสามารถใช้งาน rails sprintf ซึ่งมีให้ใช้งานอยู่แล้ว<br />
<span id="more-470"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">&nbsp;
  <span style="color:#CC0066; font-weight:bold;">sprintf</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'%04i'</span>, <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;">#result 0001</span></pre></td></tr></table></div>

<p>แล้วถ้าเกิดผมต้องการใช้ตัวเลขมี prefix และ auto generate อัตโนมัติเมื่อสร้างขึ้นมาจะทำอย่างไรลองมาดูกันครับ สำหรับเลขชุดที่ผมต้องการตอ้งขึ้นต้นด้วย TX01H และมีลำดับตามเป็นเลข 4 ตัวเรียกกันไปครับคือ 0001&#8230; มาดูโค้ดกันครับ</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">&nbsp;
  <span style="color:#0066ff; font-weight:bold;">@last_txaction</span> = Txaction.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:first</span>,:conditions<span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;code like ?&quot;</span>,<span style="color:#996600;">&quot;TX01H%&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>,:order <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;code desc&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;">#find last code result =&gt;TX01Hxxxx</span>
  code = <span style="color:#0066ff; font-weight:bold;">@last_txaction</span> ? <span style="color:#0066ff; font-weight:bold;">@last_txaction</span>.<span style="color:#9900CC;">code</span>.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;TX01H&quot;</span>,<span style="color:#996600;">&quot;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_i</span><span style="color:#006600; font-weight:bold;">+</span><span style="color:#006666;">1</span>:<span style="color:#006666;">1</span> <span style="color:#008000; font-style:italic;">#if not found start code from 1</span>
  <span style="color:#0066ff; font-weight:bold;">@txaction</span>.<span style="color:#9900CC;">code</span> = <span style="color:#996600;">&quot;TX01H&quot;</span><span style="color:#006600; font-weight:bold;">+</span><span style="color:#CC0066; font-weight:bold;">sprintf</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'%04i'</span>, code<span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<p>เป็นอันว่าเรียบร้อยครับ</p>

<p class="sayac_bilgi">12 views</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iearn.in.th/2009/05/17/number-format-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

