xreaã§Rails 2.1ãåãã
æé ã©ããã«ãã£ã¦ããã°xreaä¸ã§railsã¢ããªãåãããã¯ãã§ãã
注æï¼ã¨ãããããxreaã§Railsãåãããã¨ã«ã¯æåãã¦ãã¾ãããfast cgiã§ã¯åããã¦ãã¾ããã
æ¹éã»æ¡ä»¶
xreaã§Rails2.1ãåãããã®ããæ¤è¨¼ãããtodoã管çããç°¡åãªã¢ããªãä½æããxreaä¸ã§CRUDã§ãããã¨ã確èªããããã®ä»æ¡ä»¶ã¯ä»¥ä¸ã®éã
- ãµã¼ãã¼ã§ã¯productionç°å¢ã§åããã
- DBã«ã¯sqlite3ã使ç¨ããã
- xreaã®ãµããã¡ã¤ã³æ©è½ã使ã£ã¦ããã¡ã¤ã³ã®ãããã§åããã
- 試ããã®ã¯xreaã®ææå¥ç´ãã¦ãªãã¢ã«ã¦ã³ã
æé
ãã¼ã«ã«ã§ä½æ¥
- Railsããã¸ã§ã¯ããä½æãã
- ããã¸ã§ã¯ãããµã¼ãã¼ã«ã¢ããããæºåããã
ãµã¼ãã¼ã§ä½æ¥
- ãã¡ã¤ã³ã®è¨å®ããã
- Rubygemsãã¤ã³ã¹ãã¼ã«ãã
- Railsããã¸ã§ã¯ããå±éãã
- Railsãåããè¨å®ããã
Railsããã¸ã§ã¯ããä½æãã
ä»åã¯æ¤è¨¼ç¨ã«ã¿ã¹ã¯ã ããç»é²ã§ããç°¡åãªscaffoldãä½æããã
rails todo
cd todo
script/generate scaffold task title:string
ããã¸ã§ã¯ãããµã¼ãã¼ã«ã¢ããããæºåããã
productionç°å¢ã§ä½¿ç¨ããsqlite3ã®DBãã¡ã¤ã«ãä½æãã¦ãããã¸ã§ã¯ãã¨ãã£ããã«ãµã¼ãã¼ã«ã¢ãããã¼ããããï¼ããããã£ã¦ããã¨ããµã¼ãã¼å´ã§DBãä½æãè¨å®ããªãã¦ããï¼
rake db:migrate RAILS_ENV=production
次ã«vendor/railsã«railsã®ã©ã¤ãã©ãªãå±éãããrailsã¯vendor/railsãããã¨gemã§ã¯ãªããã¡ãã使ãã®ã§ãå¾ã ãµã¼ãã¼å´ã§railsã®ã¤ã³ã¹ãã¼ã«ãããªãã¦ããã以ä¸ã®ã³ãã³ãã§gemã§ã¤ã³ã¹ãã¼ã«ããã¦ããrailsã®ãã¼ã¸ã§ã³ã¨åããã®ãvendor/railsã«å±éããã
rake rails:freeze:gems
ãã¡ã¤ã³ã®è¨å®ããã
ããããã¯ãµã¼ãã¼å´ã§ä½æ¥ãxreaã®è¨å®ç»é¢ã¨SSHã³ã³ã½ã¼ã«ã使ç¨ããã
xreaã§ã¯ãµããã¡ã¤ã³æ©è½ã使ã£ã¦ãhttp://todo.domain.com/ãå©ãã¨ãpublic_html/todo.domain.comã¸ã®ã¢ã¯ã»ã¹ã«ãããã¨ãã§ããããã¡ã¤ã³ã®è»¢éè¨å®ã»ãµããã¡ã¤ã³è¨å®ã¯ããã«åæ ãããªããã¨ãããã®ã§æ³¨æã
ãã¡ã¤ã³è»¢éã®è¨å®ããã
ã¾ãããtodo.domain.comããxreaã®ãµã¼ãã¼ã«åãããã«ãããç§ã¯ããªã¥ã¼ãã¡ã¤ã³ã使ã£ã¦ããã®ã§ã以ä¸ã®ããã«è¨å®ããã
管çç»é¢ã®DNSè¨å®ããããa * xreaãµã¼ãã¼ã®IPãã追å ã*ã«ããã¨todo.domain.comã§ãblog.domain.comã§ããªãã§ããã©ã¯ã¼ãããã®ã§ãå¾ããã¢ããªã追å ãã¦ãåè¨å®ã®å¿
è¦ããªãã
ãµããã¡ã¤ã³ãè¨å®ãã
âã§è¨å®ãã転éãåæ ããã¦ããªãã¨ãã¾ããããªãã®ã§ããã³ãã³åç»ãè¦ãªããæéãæ½°ããã¨ã
xreaã®ç®¡çç»é¢ãããã¡ã¤ã³ã¦ã§ãã«é²ã¿subã®ã¨ããã«ãtodo.domain.comãè¨å®ããã
Rubygemsãã¤ã³ã¹ãã¼ã«ãã
vendor/railså ã«railsãå±éãã¦ããã°gemsã¯ãããªãã¨æã£ã¦ããã®ã ããã©ãããå¿ è¦ãªããããªãç¶æ ã§ã¯èµ·åã§ããªãã£ãããã£ã¦å°ããã¨ã¯ãªãã®ã§SSHã§ãã°ã¤ã³ãã¦ã¤ã³ã¹ãã¼ã«ãããxreaã¸ã®SSHã¢ã¯ã»ã¹ã¯ã管çç»é¢ã®ãã¹ãæ å ±ç»é²ããSSHç»é²ããå¾ãFTPã¨åããµã¼ãã¼/ã¦ã¼ã¶ã¼/ãã¹ã¯ã¼ãã§ãã°ã¤ã³ã§ããã
以ä¸ãææ°ã®rubygemsãåå¾ãã¦ã¤ã³ã¹ãã¼ã«ããã
export GEM_HOME=$HOME/lib/ruby/gems wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz tar zxvf rubygems-1.2.0.tgz cd rubygems-1.2.0 ruby setup.rb all --prefix=$HOME
gemã³ãã³ãã¨rubyããrubygemsãè¦ããããã«ç°å¢å¤æ°ãè¨å®ããã~/.bashrcã«ä»¥ä¸ã追å å¾source ~/.bashrc
export GEM_HOME=$HOME/lib/ruby/gems/1.8 export RUBYLIB=$HOME/lib export PATH=$PATH:$HOME/bin
Railsããã¸ã§ã¯ããå±éãã
ã¾ãããã¼ã«ã«ã§ä½æããrailsããã¸ã§ã¯ãããµã¼ãã¼ã«ããããftpã§ãããã¨ããã¨ãã®ãããæéããããã®ã§ãtar.gzã«åºãããã¨scpã§ã¢ãããã¼ãããã°ããã¨æãã
ã¢ãããã¼ããããã¡ã¤ã«ãå±éãããå±éå ã¯public_html以ä¸ã§ã¯ãã¨ããã«å±éãããpublic_htmlã«å±éããã¨ãè¨å®ãã¡ã¤ã«ãrbãã¡ã¤ã«ãé²è¦§ã¾ãã¯å®è¡ããã¦ãã¾ãå¯è½æ§ãããã$HOMEã«appsãªã©ã®ãã£ã¬ã¯ããªãä½æãã¦å±éããã¨ããã ããã$HOME/apps/todoã«å±éãã$HOME/apps/todo/public以ä¸ã®ã¿å ¬éããããè¨å®ããã
Railsãåããè¨å®ããã
public_htmlããããã¸ã§ã¯ãã®publicã«ãªã³ã¯ãã¯ãã
ã·ã³ããªãã¯ã»ãªã³ã¯ãã¯ããã¨ã§ãpublic_html/todo.domain.comã¸ã®ã¢ã¯ã»ã¹ã$HOME/apps/todo/publicã¸åãããã«ããã
ln -s $HOME/apps/todo/public public_html/todo.domain.com
ããã§ãhttp://todo.domain.comâpublic_html/todo.domain.comâ$HOME/apps/todo/publicã¨è»¢éããrailsã«ãã¡ã¤ã³ãããããã¢ã¯ã»ã¹ã§ããããã«ãªã£ãããã®ç¶æ ã§http://todo.domain.com/ã«ã¢ã¯ã»ã¹ããã°ãRailsã®ããããã¼ã¸ã表示ãããã¯ãã ã
dispatch.cgiã®rubyã®ãã¹ãä¿®æ£
$HOME/apps/todo/public/dispatch.cgiã®ä¸è¡ç®ã®rubyã¤ã³ã¿ããªã¿ã®ãã¹ãä¿®æ£ããã
#!/usr/bin/env ruby
ã§OKã
ç°¡åã«èª¬æããã¨ãpublic以ä¸ã«ã¯railsã®çµã¿è¾¼ã¿ãµã¼ãã¼ä»¥å¤ã®Webãµã¼ãã¼ã¨é£æºãããããã®ãdispatch.cgiã¨dispatch.fcgiãç¨æããã¦ãããdispatch.fcgiã¯fast cgiç¨ãxreaã®å ´åãapacheããããã®ãã¡ã¤ã«ãå¼ã³åºããã¨ã§railsãèµ·åãã¢ããªã使ããããã«ãªãã(ãããã¸ãã¯ã¾ã ã¡ããã¨ç解ãã¦ãªã)
éããããã®ã§fast cgiç¨ã使ãããã®ã ããgemã®fcgiãã¤ã³ã¹ãã¼ã«ã§ããªãã£ããããããã¯å¦¥åãã¦ã¨ããããdispatch.cgiã§åããã¦ããã
.htaccessã®è¨å®
ãã¨ã¯ãapacheãdispatch.cgiãå¼ã³åºããè¨å®ã¨ãrailsèµ·åæã®ç°å¢å¤æ°ãè¨å®ããã ãã ã$HOME/apps/todo/public/.htaccessã以ä¸ã®ããã«è¨å®ããã
RewriteEngine On RewriteRule ^(.*)$ dispatch.cgi [QSA,L] SetEnv RUBYLIB /virtual/ãã°ã¤ã³id/lib SetEnv RAILS_ENV production
å ¨ã¦ã®ã¢ã¯ã»ã¹ãdispatch.cgiã«rewriteãããrubygemsã¸ã®ãã¼ããã¹ã追å ãããrailsãproductionã§èµ·åããã¨ããè¨å®ããã¦ãããapache + railsã®é£æºã«ã¤ãã¦æ¤ç´¢ããã¨ã.htaccessã¯railsããã¸ã§ã¯ããä½æãã段éã§ä½æããã¦ãããããªæããªã®ã ããç§ã®å ´åãªãã£ãã®ã§æ°ãã«ä½æããã
ããã§railsã¢ããªãåãããã«ãªã£ã¦ããã¯ãã ãhttp://todo.domain.com/tasksããã¿ã¹ã¯ã®CRUDãè¡ããã
è¬è¾
以ä¸ã®ã¨ã³ããªã¼ã«é常ã«ãä¸è©±ã«ãªãã¾ããããããã¨ããããã¾ããã
http://tam.qmix.org/archives/2005/03/xrea_ruby_on_ra.html
http://www.rubygems.org/read/chapter/3