Ruby on Rails

Rails는 Ruby 기반의 Web App Framework이다.

특징을 꼽아본다면,

  • Model-View-Controller 패턴을 채택하고 있다.
  • 단순하고 강력한 OR mapping을 제공한다.
  • CRUD logic을 자동으로 생성해준다.

아직 Rails의 ‘The Seeing Is Believing Lesson’을 보지못했다면, 지금 바로 보길 바란다. Web App Framework를 어느 정도 경험해본 사람이더라도, 엄청나게 빠른 prototyping에 놀랄 것이다. 설치부터, 간단한 blog의 prototype 구현까지 10분이면 된다니, 놀랍지 않은가.

불과 수시간 정도 경험해보고나서 판단을 내리기에는 무리일지 모르겠지만, Rails의 빠른 prototyping은 Model, View, Controller의 mapping이 name-based로 이루어지는 점과, OR mapping (DB table과 Model class의 mapping) 역시 name-based로 이루어진다는 점, 그리고 CRUD를 자동으로 생성해주는 점에 기인한다고 생각된다. 다른 Web App Framework를 약간이라도 들여다본 사람이라면 알아차리겠지만, 그러한 framework에서는 확장성을 위한 추가적인 노력이 필요하기 때문에, Rails에서 얻을 수 있는 빠른 prototyping 능력을 희생하고 있다고 볼 수 있다.

다만, OR mapping을 할 때, DB table을 만든 후, Model class가 table에 따라 생성되므로, 설계가 data-oriented 화할 가능성이 커지지 않을까 하는 우려가 있다. 이 부분에 대해서는, 아직 Rails를 충분히 경험하지 못했으므로, 더이상의 언급은 나중으로 미루는 것이 좋을 듯 하다.

다음은 ‘A Guide to Testing the Rails’를 보면서 작성한 Rails application이다.

http://www.lastmind.net/rails/todo/list

Tutorial을 따라가는 동안 내내 즐거웠고, 거의 막힘없이 진행하기는 했으나, 아쉽게도 host의 root로 Rails 설치 위치를 alias하지 않은 경우에(나는 http://www.lastmind.net/이나 http://rails.lastmind.net/이 아니라, http://www.lastmind.net/rails 아래에 Rails app을 설치했다.), mod_rewrite를 이용하는 RewriteRule이 문제가 생겨서, 약간의 손질이 필요했다. 다음이 그 내용이다.

# Make sure that mod_ruby.c has been added and loaded as a module with Apache
RewriteEngine On
# Change extension from .cgi to .fcgi to switch to FCGI and to .rb to switch to mod_ruby
RewriteBase /rails/dispatch.cgi
# Enable this rewrite rule to point to the controller/action that should serve root.
# RewriteRule ^$ /controller/action [R]
# Add missing slash
RewriteRule ^([-_a-zA-Z0-9]+)$                                            $1/
# Default rewriting rules.
RewriteRule ^([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)/([0-9]+)$                  ?controller=$1&action=$2&id=$3 [QSA,L]
RewriteRule ^([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)$                           ?controller=$1&action=$2 [QSA,L]
RewriteRule ^([-_a-zA-Z0-9]+)/$                                           ?controller=$1&action=index [QSA,L]
RewriteRule ^([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)/([0-9]+)$ ?module=$1&controller=$2&action=$3&id=$4 [QSA,L]
RewriteRule ^([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)$          ?module=$1&controller=$2&action=$3 [QSA,L]
RewriteRule ^([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)/$                          ?module=$1&controller=$2&action=index [QSA,L]

최근에 Ruby를 사용한 Web app를 이것저것 만들고 있었는데, OR mapping에 시간을 불필요하게 많이 소비하고 있었고, view에 있어서 templating이 매우 필요했는데, 이러한 점들 모두 Rails가 해결해줄 수 있을 것 같아서 기쁘다. 앞으로는 기존 ruby web app들(RSS reader, link gallery, ..)을 Rails로 porting 해 볼 생각이다.

댓글 달기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.