I'm a Ruby on Rails / jQuery web developer. Follow me at @sikachu

Hoptoad ❤ Heroku

Wednesday, December 15th, 2010 Posted in My Project, Ruby, Ruby on Rails | No Comments »

Recently, I've started to migrate my application to Heroku. While most of the functionalities are there, one of the thing I was missing is Hoptoad's deploy tracking, as you cannot add a deploy hook to call Rake task as you ...

`method_missing` call stack in Ruby

Tuesday, November 23rd, 2010 Posted in Programming, Ruby | 2 Comments »

Just found out something cool from reading "Don’t Know Metaprogramming In Ruby?" from RubyLearning blog. Consider this code snippet: class Person end class Student < Person end class HighSchoolStudent < Student end If you're calling some method that's undefined, let's say we're calling HighSchoolStudent#name Ruby will try ...

Gems — Follow up from my talk at #BarcampBKK4

Friday, October 29th, 2010 Posted in Programming, Ruby, Ruby on Rails | No Comments »

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 ...

10 Things you should know about Ruby — #BarcampBKK4

Sunday, October 24th, 2010 Posted in Programming, Ruby | 2 Comments »

I'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 ...

Ruby 1.9.2 is out!!

Wednesday, August 18th, 2010 Posted in News, Programming, Ruby, Ruby on Rails | 1 Comment »

Just got the news in Twitter today that Ruby 1.9.2 is out! This is the Ruby that we've been long-awaits which shouldn't have any strange compatibility issue with the upcoming Rails 3, and wayyyy faster than 1.8.7. The timing couldn't be ...

Operator Precedence ใน Ruby

Saturday, December 19th, 2009 Posted in Programming, Ruby | 1 Comment »

Operator Precedence หรือลำดับสำคัญของตัวดำเนินการนั้น ถือเป็นหลักสำคัญของโปรแกรมเมอร์ ที่จะทำให้สามารถทำการเขียนอัลกอริธึมเพื่อแก้ไขปัญหาต่างๆ ได้ ในทางคณิตศาสตร์นั้น มักมีคนสรุปมันออกมาง่ายๆ ว่า "วงเล็บมาก่อน คูณหารก่อนบวกลบ" ถ้าใครเคยเห็น code ภาษา Ruby นั้น คงจะเคยเห็นว่า Ruby นั้นมีทั้ง operator && และ || เหมือนกับในภาษา C แล้วยังมี and กับ or ที่เพิ่มเข้ามาใน Ruby ซึ่งเป็นสิ่งที่ทำให้โค้ดนั้นดูสวยงามขึ้น อ่านง่ายขึ้นตามหลักของ Ruby ลองดูโค้ดด้านล่างนี้เป็นตัวอย่างครับ irb(main):001:0> dessert = "Cheesecake" => "Cheesecake" irb(main):002:0> drink = "Coffee" => ...

Optimize database query ด้วย :include

Friday, August 7th, 2009 Posted in My Project, Programming, Ruby, Ruby on Rails | 1 Comment »

ในการเขียนโปรแกรมบน Ruby on Rails นั้น เรามักที่จะใช้ ActiveRecord ในการทำหน้าที่เป็น ORM ระหว่างตัว Application กับ database ซื่งทำให้การเรียก Record นั้น สามารถทำได้อย่างง่ายดาย เช่น ถ้าผมจะเรียกดู post ทั้งหมดที่มีอยู่ในระบบ ผมแค่สั่ง Post.find(:all) # หรือว่า Post.all ก็ได้ ใน Rails 2.x ซึ่งตรงนี้ ถ้าเราไปดูใน Log file จะพบว่า ActiveRecord นั้น จะใช้คำสั่งค้นหาข้อมูลประมาณนี้ครับ ...

Thin Rolling Restart Patch

Sunday, August 2nd, 2009 Posted in My Project, Programming, Ruby, Ruby on Rails | Comments Off

I wrote a patch for Thin web server to do a rolling restart (i.e. restart the server one at a time) when I was working for my final thesis, Localmapia. I put my source on Github, and already inform the ...

Object#try ใน Rails 2.3

Sunday, August 2nd, 2009 Posted in My Project, Programming, Ruby, Ruby on Rails | Comments Off

เคยเจอปัญหาบ้างไหมครับ กับการที่บางครั้ง object ที่เราเรียก method ไปเนี่ย มันกลายเป็น nil ขึ้นมา ทำให้เกิด exception ขึ้นมา >> @user.username NoMethodError: You have a nil object when you didn't expect it! The error occurred while evaluating nil.username from (irb):1 ซึ่งตรงนี้ เพื่อที่จะหลบ exception ในบางครั้งทำให้ Developer ต้องทำการเช็คก่อนว่า object นั้นเป็น nil หรือไม่ เช่น >> (@user ...

Ruby และ active_support/whiny_nil

Monday, June 29th, 2009 Posted in My Project, Programming, Ruby, Ruby on Rails | Comments Off

สำหรับนักพัฒนาส่วนใหญ่ที่เริ่มเขียน Ruby on Rails คาดว่าตอนนี้ในเครื่องของทุกๆ คน น่าจะลง Ruby 1.8 อยู่ เนื่องจากยังคงมี Gem หลายๆ ตัว ที่ยังไม่รองรับ Ruby 1.9 และทำให้เกิดปัญหาทางด้านความเข้ากันได้อยู่บ้าง ฉะนั้นผมเลยอยากพูดถึงหลุมพรางที่ Ruby 1.8 ได้ทิ้งเอาไว้ และทำให้หลายๆ คนนั้นพลาดตกหลุมกันไปบ้างครับ ผมขอสมมุติเอาไว้ว่า ผมได้สร้างระบบ Blog แห่งหนึ่ง โดยที่มี Model สามตัวคือ Post เอาไว้เก็บข้อความ Comment เอาไว้เก็บความคิดเห็น และ User เอาไว้เก็บชื่อผู้ใช้ ที่สามารถแก้ไขข้อความได้ครับ สมมุติว่า User ที่สามารถเข้ามาแก้ไขได้นี้ ...