ã¼ããè¦ã¦ããã¬ã¼ã«(map.resoucesç·¨)
å
æ¥ã®QConã§å¤§å ´ããããã£ããã£ã¦ãããã¨ã§ãããRailsã§éçºãããä¸ã§ãã®ãããéè¦ãªãã¤ã³ãã«ãRailsã®æ·ããã¬ã¼ã«ããéããªãã¨ããã®ãããã¾ããå¥ã«ã³ã¬ã¯Railsãä¸èªç±ã ã¨ããããã§ãªã*1ãéãä¸éã®ãã®ããã§ããªãã¨ããããã§ããªãããã åºç¤ã¨ç¸æ§ã®æªãè¨è¨ããã°ãã¨ã§è¦å´ããã¨ãããå½ç¶ã®è©±ãªããã§ãã
æè¿ãç§ãå«ããããããªæ¹ããã¬ã¼ã«ããéããªãã§ä½ãã®ãéè¦ãã¨è©±ãã¦ãã¾ããããããããã®ã¬ã¼ã«ã¯ã©ãã«ããã®ãã¨ãã話ã¯ãã¾ãèããã¾ãããã¨ãããã¨ã§ããµã ãç§ãRailsã¢ããªãè¨è¨ããã¨ãã«æèãã¦ããã¬ã¼ã«ãè¨èªåãã¦ã¿ã¦ãè°è«ãªãã®ãããå°ã«ããããªãã¨æã£ã次第ã§ãã
ã¨ã¯ããDBå¨ãã¯ãç¾½çããã®ERDã¬ãã¹ã³å«ãã§7å²ãããæ¸ã話*2ãªã®ã§ãã¾ãã¯ã³ã³ããã¼ã©ããã
è¨è¨æéã¨ãã¦ã®map.resouces
Rails 2.xã«ããã¦ãã³ã³ããã¼ã©ã®è¨è¨ã¨ããã®ã¯ã¤ã¾ãã¦ã¼ã¶ã«å¯¾ãã¦æä¾ãããªã½ã¼ã¹ã®è¨è¨ã«ä»ãªãã¾ããããã®ã¨ãæ°ãã¤ãã¦ãããã¨ã¯ãscaffoldã«ä¼¼ããããè¨ãæããã¨ããªã½ã¼ã¹ã®CRUDãæèãããã¨ãããã¨ã§ãã
ããå°ã極端ã«è¨ãã¨ãmap.resoucesãã¡ããã¨ä½¿ã£ã¦ãããã¨ããæãã§ããRailsã¬ã·ãããã¯ã«ãæ¸ãã¾ããããmap.resoucesã¯ã¨ã¦ãããæãã«ã«ã¼ãã£ã³ã°ãå®ç¾©ãã¦ããã¾ããããªãã¡
- è¤æ°ä»¶åå¾ (index, GET /resouces)
- ä¸ä»¶åå¾ (show, GET /resouces/:id)
- ä¸ä»¶ä½æ (create, POST /resouces)
- ä¸ä»¶åå¾ (update, PUT /resouces/:id)
- ä¸ä»¶åé¤ (destroy, DELETE /resouces/:id)
ã®5ã¤ã§ããããã®5ã¤ã§ãã¾ããªã½ã¼ã¹ãCRUDã§ããããã«ä½ãã®ãåºæ¬ã ã¨æã£ã¦ã¾ãã
ã»ãã«ãæ°è¦ä½æç»é¢(new)ã¨ç·¨éç»é¢(edit)ãããã¾ãããã¢ã¬ã¯ãªã½ã¼ã¹ã®CRUDã«ã¯ç´æ¥é¢ä¿ãªãã¢ã¯ã·ã§ã³ã ã¨å²ãåãã¨ãããã¨æãã¾ããããã¯å ¥åè£å©ç»é¢ã¨ããããç義ã®UIã¨ãããã
ã³ã³ããã¼ã©ã®è²¬å
ã§ãã³ã³ããã¼ã©ã®åã¢ã¯ã·ã§ã³ã§å®è£ ãã¹ã責åã®ãã¡æãéè¦ãªã®ã¯ä¸è¿°ã®map.resoucesããå°ãããããããã®å½¹å²ãæãããã¨ã§ããå½ç¶ã§ãããè¦ããã«é©åãªãªã½ã¼ã¹ããã¼ããã¦ããªã½ã¼ã¹ã®ãã¸ãã¯ãããã¯ãã¦ããããã¨ã§ããããã«ããä¸ã¤ã¯ã¦ã¼ã¶ã«ã¬ã¹ãã³ã¹ãè¿ããã¨ãã³ã¬ã¯redirectãããé©åãªãã³ãã¬ã¼ããrenderãããããã£ã¦ãã¨ã§ãã
èªã¿åãç³»(index, show)ã®ã¢ã¯ã·ã§ã³ã§ããã°ãç®çã®ãªã½ã¼ã¹ãã¡ããã¨æ¤ç´¢ãã¦ãã¼ããããã¨ã主ãªè²¬åã§ãããã¾ã ã¨named_scopeãªããã使ãã¨ããããããªãã§ããããã
æ¸ãè¾¼ã¿ç³»(create, update, destroy)ã§ããã°ãç®çã®ãªã½ã¼ã¹ããã¼ããããnewãããããä¸ã§ãsaveã¨ãdestroyã¨ãæ¥åçã«å¿
è¦ãªé¡ä¼¼ã¡ã½ãããªã©ãããã¯ãããã¨ã第ä¸ã®è²¬åã§ããããã«ãã®çµæãããã¦ãå
¥åè£å©ç»é¢ããå表示ããããã§ãããªã½ã¼ã¹ã¸é·ç§»ãããããã¨ããã¨æãã¾ãã
ããã®çµã¿åããã§ãã¾ãè¦æ±ä»æ§ãæºããããã«ããªã½ã¼ã¹ãè¦ãã ãããã«å¿ãããã¨ããæãã§ãããã¡ããè¦ãã ãã®ã¯é£ããã§ããã©ãå°ãªãã¨ãæ¹åæ§ãæèãã¦ããã¨ããããããªãã§ããããã
ã§ãè¦ãã ãããã¨ã®å®è£
ã¯scaffoldã§çæãããã®ãã ãã¶ããæããªã®ã§ããããèªãã§ã¿ã¦ãã ãããªã
ç¶ããã
ä¾ã«ãã£ã¦çãã¾ã¨ããããªãã£ãã§ãããããªæãã§ãç¶ããã¿ã¨ãã¦ã¯
- ããè¦ãã¯ã¾ãã©ãã
- 確èªç»é¢ => ããJSã§
- ã¦ã£ã¶ã¼ã => ããJSã§
- è¤æ°é ç®ãä¸æ°ã«å ¥å => ããJSã§
- ã¢ãããã¼ãå 容ããã¬ãã¥ã¼ => ä»æ§ãè½ã¨ãorã¬ã³ãã¬!!
- ãã¥ã¼ã¨ã³ã³ããã¼ã©ã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ => paramsã«ã¢ãµã¤ã³ãããä»çµã¿(ã¬ã·ãæ¬ã«æ¸ããã!!)
- ã³ã³ããã¼ã©ã¨ã¢ãã«ã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ã®ä½ãæ¹ => åºæ¬ã¯Hashã¨æååã¨é
åãããRubyã ã
- ãã¢ãã«ãã¨ããªã½ã¼ã¹ãã¯ä½ãéãã®? => ã ãããåãããã«æ±ããã©æ©å«ã¨ã·ã¹ãã å ã§ã®æå³ãéããããã ãåã«å¸½åéãã ã£ããããããã¨ããããªã
- ã¢ã¯ã»ã¹æ¨© => scope_doã®è©±ãããã¨ãã«ãæ¸ãã
- ã«ã¼ãã£ã³ã°ã®ãã¹ãã¨ARã®ã¢ã½ã·ã¨ã¼ã·ã§ã³
- ãã¹ãã®æ¸ãæ¹ => ä»å°ã§è©±ãã
- Cucumberã§å¤å ãåãã
- step_definitionsã¨ãã«ã¹ã¿ã matcherã¯ãããã¸ã§ã¯ãå ã§"è²ã¦ã¦"ããã®ãããããããªãã!!
ã®ããããããä¸åº¦ã¾ã¨ãã¦ãããã¨ãããªãã¨æãã¾ãã