You need to install the development tools. On Ubuntu this would be the package build-essential, plus some others. I don't know whether it will help but googling for
install ruby rails qnap
found this [1] and others
If possible I suggest that you use rvm to install RoR.
Colin
[1] [Tutorial] Ruby 1.9.2, Rails 3.1 on QNAP 219P+ - QNAP NAS Community Forum