Railsåå¼·ä¼@æ±äº¬ 第7å ã«è¡ã£ã¦ãããä»åã¯ããªã³ã æµæ¯å¯¿ãªãã£ã¹ã«ã¦ã
å°é¨ã®éãä¸ãåå è ãããããã¨éã¾ã£ã¦ãããæ®ãã®äººãå¾ ã£ã¦ããéã話é¡ã«ãªãã®ã¯ æ¨æ¥ã®ã¯ã¶ã«ã£ã ã®ãã¨ãã¯ã¶ããããæ示ããããRailsã®ããããã¯DOAã¸ã®éåã§ã¯ãªãããã¨ããçåã¨ãããã¤ãã®è³ªåãããã¦ããã¸ã®id:takahashimãã¨é«æ©ä¼é·ã®ã³ã¡ã³ããããã¯æ親ä¼ã®è©±é¡ã«ãç¶ããã
ããªã³ã ã®ãªãã£ã¹ã¯ããªã¤ã¼ãå°ãè¨ç½®ãããç´ æµãªæãã
ååã»ãã·ã§ã³
4ã¤ã®ã»ãã·ã§ã³ã«åãããã
- DHHã®è¬æ¼ã®é²é³ãè´ã
- ãARã詳ãããããã¨ã§èªã
- Railsã®ããã©ã¼ãã³ã¹åé¡ã®è±èªã®ããã¹ããèªã
- AWDwRã®ä»é²Aãèªãã
ç§ã¯ãRailsã®ããã©ã¼ãã³ã¹åé¡ãã«åºãããã¿ã«ããã®ã¯ A Look at Common Performance Problems in Rails ãããã¿ããããã®è¨äºãæã£ã¦ãã¦ç´¹ä»ãã¦ããã¦ãã¿ããªã§èªãã§ã¿ãã
å 容ã¨ãã¦ã¯ç´°ããªãã¦ãã¦ã®å¡ã¨ããå°è±¡ã
ç¹ã«ãlink_toã®ä»£ããã«ããªã³ã¯å URLãERbã§ãã¿æ¸ããããã¨ããã®ã¯ã¾ãã«ããããã¦ãã¦ãã¿ããªããã£ã¦å対ããã確ãã«ãlink_toã¯Routingãåç §ããããé ããã ãã©ãããããã¯å ã«ãã¼ã¸ãã¨ã®ãã£ãã·ã³ã°ã§ãªãã¨ãããããªã¼ã¨ã
é¢é£ãå°éã«è¾¿ããã㯠findã§:includeãããã¨ããã®ã¯ãã¾ãã¾ã®äººãè¨ã£ã¦ãã話ã§ããã£ã¨ããã§ãä¸ç·ã«åºã¦ãã:joinã®å ´åãç°¡åã«ããæ¹æ³ã¯ ãã¾ãã¾ã®äººãæ¸ãã¦ã ã
ãªã¯ã¨ã¹ãURLãRouteã«ããããããã®ãæå¤ã«ã«ã³ã¹ããæããã®ã§ããã使ãRouteãä¸ã«æ¸ãããã¨ãããã©ã«ãã§ã¯wsdlã¸ã®routeããããã«æ¥ã¦ããããã©ãããã¯conflictããªããã°å¾ãã«ç§»ããã»ããããããã®å ´ã§èãã話ã§ã¯ãå®ã¯config/routes.rbã®è¨å®ãã1è¡è¿½å ããã¨ã100ããªç§/ãªã¯ã¨ã¹ããããé£ããã¨ããããããã
ãã¨ã¯ãã»ãã·ã§ã³ã¯PStoreé ãããmemcachedã§ããã¨ãã
å ¨ä½ã¨ãã¦ã¯Railsã®ã½ã¼ã¹ãèªãã§ããããªããã¢åãã®ææ¸ã§ã¯ãªãã¦ãRailsãä½ããããä½ã¨ããã¦ãããã¨æã£ã¦ããåå¿è åãã«ããä½ã¨ããã¦ãããªãé¨åããã¤ã¼ãæ¼ããã¦æ¸ãã¦ããã¨ããå°è±¡ãã¨ãããããä¸åº¦èªãã§ã¿ãã¨ãããã§ã¯ãªãã§ãããããã§ãå ¨é¨ãéã«åããå¿ è¦ã¯ãªãã§ãã
ä»ã®ã»ãã·ã§ã³
DHHã®è¬æ¼ã®é²é³ãè´ã
æ¥æ¬Rubyã«ã³ãã¡ã¬ã³ã¹2006ã§ã®è¬æ¼ã®é²é³ãã¿ããªã§èããããããå 容㯠å®è¤ããã®ã㤠ã詳ãããCRUDéè¦ã
ãARã詳ãããããã¨ã§èªã
åããæ¥æ¬Rubyã«ã³ãã¡ã¬ã³ã¹2006ã§ã®ãã¾ãã¾ã®äººã®ã ActiveRecordã詳ãã ãã®ãã¬ã¼ã³è³æãå ¬éããã¦ããã®ã§ããããèªãã ã
AWDwRã®ä»é²Aãèªã
Railsåå¿è åãã«ãRailsã®ããã®Rubyãå¦ãã ãMarshalãããã¾ã§èªãã ãããã
å¾åã»ãã·ã§ã³
å¾åã»ãã·ã§ã³ã®ãé¡æ±ºãã¯ããããæåãã ã¯ã¶ããã®è¨äº ã¸ã®è¿çãèãããã«ã³ã¢ãªã²ã¨ãã¡ãéä¸ãã¦ä»ã®ã»ãã·ã§ã³ãæç«ããªããããããªãã£ãã®ã§ãå®éããããè¬éãã¦ã¿ã¦ãã¯ã¶ããã¯DBè¨è¨ã«é¢ãã¦ã¯ããã人ãªããã§ãDBã¾ããã«é¢ãããã®ææã¯ã¨ã¦ãå¼·çã§ããããæãä¸ãã¦ãããèãã¦ãèããããªãã¨ãããã¨ã¯ãªãã人ãéã¾ãã®ãä»æ¹ããªãã®ã ããã©ãã§ããã®ãã¿ã¯ãæ親ä¼ã§ãã§ãããããã¨ãããã¨ã§å°å°ãããã
çµå±ããããªã»ãã·ã§ã³ãéãããã
- Rubyã¡ã¿ããã°ã©ãã³ã°å ¥é : ActiveSupportã¨ã
- AR(Active Record)ã¢ããªã³ã°å ¥é
- Linux Journalã®DHHãæã§ã
ç§ã¯ãARã¢ããªã³ã°å ¥éãã«åºããã½ã¼ã·ã£ã«ããã¯ãã¼ã¯ãµã¼ãã¹(SBS)ãé¡æã«ãããã¨ã«ãã¦ãã¾ãã¯ã¿ããªã§è©±ãåããªããSBSãã¢ããªã³ã°ãã¦ãã£ãã
id:moroããã¨ãç§ã¨ããããããã¹ãã人ãã¡ãã¯ã¶ããã®ABD(Activity Based Datamodel)ã®ä¿¡å¥è ã ã£ãããã§ãã©ããã¦ããªã½ã¼ã¹ç³»/ã¤ãã³ãç³»ã¨ããABDã®æµåã«æã¾ã£ãã¢ããªã³ã°ã«ãªããã¡ã ã£ãã ã¤ãã«ãªã®äºº ã®è¦³å¯ã«ããã°ããããã¼ãã«è¨è¨ããã¡ãã¨ã§ããªãã¨Railsã¯ä½¿ãããªããªãããã¨ã証æãããã®ãåããã¨æ ã£ãããã ã
å ¨ä½ã«ãä»ã¯Railsã§ã交差ã¨ã³ãã£ãã£ããã£ããã¨ã¢ãã«åããæµãã«ãªã£ã¦ãããAWDwR 2nd ed.ã§ãHABTM(has_and_belongs_to_many)ã®èª¬æã¯å²æããã¦ãRailsã®éçºæ¹éã¨ãã¦HABTMã®ä»£ããã«has_many :through => ...ã®ä½¿ç¨ãæ¨å¥¨ããã¦ãããé¢é£ãã¼ãã«ããããã«é¢é£ãæ´¾çããã®ã¯æ°æã¡æªãã¨ããæè¦ã¯ããã¤ã¤ãããã®ã»ãã·ã§ã³ã§ã交差ã¨ã³ãã£ãã£ããã£ããã¨ã¢ãã«åããæ¹åã§è©±ãé²ãã ã
ä»æ§ã¯del.icio.usãã¯ã¦ãªããã¯ãã¼ã¯ã¨ãã¾ãå¤ãããªãã
- ã¦ã¼ã¶ã¼ã¯è¤æ°ã®ãã¼ã¸ãããã¯ãã¼ã¯ãã
- åä¸ã®ãã¼ã¸ã¯è¤æ°ã®ã¦ã¼ã¶ã¼ããããã¯ãã¼ã¯ããå¾ã
- 1人ã®ã¦ã¼ã¶ã¼ã¯1ã¤ã®ãã¼ã¸ã1åããããã¯ãã¼ã¯ã§ããªã
- ã¦ã¼ã¶ã¼ã«ã¯è¤æ°ã®ããæ°ã«å ¥ãã®ã¦ã¼ã¶ã¼ãããã
- ããã¯ãã¼ã¯ã¯è¤æ°ã®ã¿ã°ãæ¯ããã
- åä¸ã®ã¿ã°ã¯è¤æ°ã®ããã¯ãã¼ã¯ã«å ±æãããã
ã¾ãã¯ãã¯ã¤ããã¼ãã«ERå³ãæãã¦ã£ã¨ãã§ããããå®éã«ActiveRecordã§æ¸ãã¦ã¿ããã³ã¼ãã£ã³ã°ã¯äºä¸ããããã£ã¦ããã¦ãã¿ããªã§ããã¸ã§ã¯ã¿çµç±ã§ãããçºããã
User
- has_many :pages, :through => :bookmarks
- has_many :favorite_users, :through => :favorites, :table_name => :users, :foreign_key => favorite_user_id
Favorites
- belongs_to :user
- belongs_to :favorite_users, :table_name => :users
Page
Bookmark
- belongs_to :user
- belongs_to :page
- has_many :tags, :through => :tagging
Tag
- has_many :bookmarks, :through => :tagging
-
- belongs_to :bookmark
- belongs_to :tag
ã¨ãããã°ABDã«è½ã¡çãããã«ãªã£ã¦ãã¾ãã®ãå¿ æ»ã«é¿ãããã¨ããã®ã§ãå¾®å¦ã«ã¯ã¶ããã®æ¨å¥¨ããããæ¹ã¨ã¯éãæãã«ãªã£ã¦ãã¨æãããã£ã¨ABDãã¦ãã»ããç§ã¯å¥½ãã ã
ããã§ã²ã¨ã¤åé¡ãä¸ã§ã¯ãusersãã¼ãã«ãfavoritesãã¼ãã«ãéãã¦many to manyãªèªå·±åç §ãæã£ã¦ãããhas_manyã®ãªãã¡ã¬ã³ã¹ã«ã¯:throughãæå®ããã¨ãã¯:foreign_keyã¯ç¡è¦ãããã¨æ¸ãã¦ãã£ã¦ãèªå·±åç §ããå ´åã®has_many :throughã®æå®ã®ä»æ¹ãããããªããçµå±ã:sourceãããã使ãã°ããããã§ã¯ãã£ãã®ã ããã©ããã®å ´ã§ã¯èª°ãã¯ã£ããã¨ã¯ããããªãã£ãããã®å¾ãåå¼·ä¼ã®ã¡ã¼ãªã³ã°ãªã¹ãã«ã¦ 解ç ãç´¹ä»ãããã
ä»ã®ã»ãã·ã§ã³
Rubyã¡ã¿ããã°ã©ãã³ã°å ¥é
ActiveSupportã®cattrã¨ããããããã®ãé¡æã«ã¡ã¿ããã°ã©ãã³ã°ãå¦ãã ãããã
Linux Journalã®DHHãæã§ã
Linux Journal #147 ãDHHã表ç´ã«ãã¦ã1ãã¼ã¸DHHã®ã¤ã³ã¿ãã¥ã¼ãè¼ãã¦ãããRubyã®ç¹éããããããããèªãã ãããã
æ親ä¼
ã¯ã¶ããã®è©±ãHaskellã®è©±ããã¤ãã®è©±ãã¿ããªã§æºå¸¯ã§ã¯ã¶ã«ã£ããè¦ã¦ããããèãã¦ã¿ãããã©ããã®äººæ°ããã®å§¿ã¯ããããã£ã½ãããid:moroããæ°ãããã ã£ã¦ãããã ãã
ãJavaã«blockã¨ãªã¼ãã³ã¯ã©ã¹ã¨ãªãã¸ã§ã¯ãã¨ãã¦ã®ã¯ã©ã¹ï¼ã¯ã©ã¹ã¡ã½ããã®å¤æ )ã¨æ°æ¥½ãªå®è¡æã¡ã½ããå®ç¾©ã¨method_missingã¨ç¶ç¶ã¨Duck typingã¨æ¬å¼§ãªãã®ã¡ã½ããå¼ã³åºããããã°Rubyãããªãã¦Javaã§ããããããã¨ãã話ããã¦ããããããä½ã¦ããC# 3.0ï¼ãã¨è¨ãããã確ãã«ãC# 3.0ã¯ããªãé¡æãæºããã¦ããããã ããã
èå¿ã®é«æ©ä¼é·ããã¯ã¶ããããã®è¿çããã£ããã¨ãã¾ã ç¥ããªãã£ããããã®ã§ãäºæ¬¡ä¼ã§ã¯é«æ©ä¼é·ãå²ãã§æ¬æ ¼çã«ã¯ã¶ããã¸ã®è¿äºãèããã
ç·è«ã¨ãã¦ã¯ãDHHãè¬æ¼ã§äº¤å·®ã¨ã³ãã£ãã£ã強調ãã¦CRUDéè¦ã¨è¨ã£ã¦ãããåºæ¬çãªæ¹åæ§ã¯åè´ãã¦ããã§ãªãããªã¨ãããã¨ãDHHã®è¬æ¼ã®æå³ãæ¬å½ã«ç¥ãããã£ããã¯ã¶ããã®ã 楽ã ERDã¬ãã¹ã³ ããèªãã¨è¨ããããããã
ããããåæ¹ã®èãã¯ã©ãã§éã£ã¦ãã®ãã¨ããã¨ããã®ç¹ã¯ id:moroãããã¾ã¨ãã¦ã ããããèªãã°ããããããã¨æãã
id:moroããã¯ãã§ãããããã¨ããã«ã客ãã¾ã®ãä½ããªããããããå¤§å¹ ã«å¤ããããè¦æ±ã«ãã¨æ¸ãã¦ããããã©ããããããã¨å¤åDBè¨è¨èªä½ãå¤ãã£ã¦ããå ´åãããã¨æãããããã¯ãç§ã®èº«ã®åãã¿ããã«ã1ã¶æãããã§å¯¾è±¡æ¥çã®æ§é èªä½ãå¤åãã¦ããå ´åãDBã®æ§é ã®å¤åã¯é¿ããããªãã¨æããã¡ãã£ã¨åã¾ã§ã®ç§ã ã£ãããããªç¶æ³ã«ç«ã¡ãããã°ããã ã£ãã¨æãããã©ãä»ã¯ãããã§ABDã§ãããã¨è¨ããã¯ã¶ããèªèº«ãABDãã©ãæãã¦ããã¯ç¥ããªããã§ãç§ã¯ Seasar Conferenceã§ABDãèããã¨ã ãDBã®æ§é èªä½ãã¿ãã¿ãå¤åãã¦ãããããªç¶æ³ã«ããã¦ãå¤åã«å¼·ãDBãä½ãæ¹æ³ã ã¨åãåã£ãã
ããããã¨ããã§ãRailsã ãã ã£ããç¾å®ã®è¦æ±ã«å¿ããããªãã¦ããABDã¨Railsãçµã¿åãããã°å¼·ãã¨ããã£ã±ãç§ã¯æãããã¨ã¯ABDãæ¯æ´ããhas_one :throughã¿ãããªæ©è½ãRailsã«è¿½å ã§ããã°é¢ç½ããRailsã«ãããABDã®å®è·µã¯æ¬¡åã®åå¼·ä¼ã§ãã¿ã«ããã
ããSeasar Conferenceã§è²°ããããªã£ããããä»åº¦ã¯ã¶ããã«ä¼ããããã®ã¨ãããERDæ¬ã«ãµã¤ã³ãã¦ããããã°ã