ããRuby on Railsããã¸ã§ã¯ãã®ãµãããã
æ¨å¹´æ«ããå§ãããRuby on Rails ã使ã£ãããä»äºãã²ã¨æ®µè½ããã®ã§ããµãããã£ã¦ã¿ã¾ããã
ãã®ä»äºã§ä½ã£ãWebã¢ããªã®è©³ç´°ã¯æ¸ãã¾ããããç»é¢æ° 60ããã¼ãã«æ° 15 ã¨å°è¦æ¨¡ã®ãã®ã§ãããã·ã¹ãã ã¯ã¨ããã©ããã«é£ããé¨åã¯ããã¾ãããUIã¯ä¸é¨ã« Ajax(JQueryã使ç¨)ãå°å
¥ã使ãåæãé«ãã¦ãã¾ãã
1. ã½ã¼ã¹ã³ã¼ããå°ãªãï¼
æ¸ããRubyã³ã¼ãã®è¡æ°ãåè¨ãã㨠ç´3600è¡ ããããã¾ããã§ããï¼ 1ç»é¢ããã 60è¡ããæ¸ãã¦ãªã !!
ã»ã»ã»ãããã¾ãä»äºãã¦ãªããããï¼ãã¨æããã¤ã¶ããã¦ãã¾ãã¾ã¾ãã ^^);
ãã¯ããRuby on Rails ã¯çç£æ§ãé«ãã¨è¨ãããéãã§ãã
ãã ããã ãã ãã¨ã³ã¼ããæ¸ããªãããã«ä»¥ä¸ã®ããã«æ³¨æãã¾ããã
å ±éé¨åã¯ã¢ã¸ã¥ã¼ã«åãMix-inã§å ±æ
ç¶æ¿ã«ããæ©è½ã®å ±æã¯è¨è¨ãé£ãããªãã¾ãããå§è²ã«ããå ±æã¯ããã©ãã§ããããã Mix-inã¯æ軽ã«å®è£ ã®å ±æãã§ãã¾ããã»ãã¨ãã«Rubyè¨èªã®è¯ããæãã¾ããã
ä¸é¨ã®å¦çã¯DSLãå®ç¾©ãã¦ä½¿ã
ä¸é¨ã®å¦çã¯DSLãå®ç¾©ãã¦ãå©ç¨ããå´ã«ã¯DSLã§æ©è½ãå®ç¾©ããããã«ãã¾ãããã©ã¤ãã©ãªã¼ã«ãã©ã¡ã¿ã¼ã渡ãã¦å©ç¨ããå ´åã«æ¯ã¹ãã¨ãDSLãå¦çããå´ã®ã³ã¼ãã¯å°ãé£ãããªãã¾ãããå©ç¨ããå´ã®ã³ã¼ãã¯å§åçã«ç°¡æ½ã«ãªãã¾ãã ã¡ã¿ããã°ã©ãã³ã°ä¸æ³ã§ãã
ã·ã³ãã«ã§å¹æãé«ãããªå ´åã¯ãRuby/Railsã®ã³ã¢ã¯ã©ã¹ãæ¡å¼µ
Ruby/Railsã®ã³ã¢ã¯ã©ã¹ãæ¡å¼µããã¨ãã¢ããªã±ã¼ã·ã§ã³ã®ã³ã¼ãã¯å°ãªãã§ãã¾ããåæã«ä¸å¯æè°ãªãã°ãä½ã£ã¦ãã¾ã£ãããRailsã®ãã¼ã¸ã§ã³ã¢ããã§åããªãã³ã¼ããä½ã£ã¦ãã¾ãå±éºæ§ãããã¾ãã
ä»åã¯ãã³ã¢ã¯ã©ã¹ã®æ¡å¼µã¯ã·ã³ãã«ãªãã®ã ãã«çµãã¾ãããããã¯ãã³ã¼ããç°¡æ½ã«ãªãã®ã¯å¬ããã§ããã
ä¾ãã°ã以ä¸ã®ãããªæ¡å¼µããã¾ãã
id = params[:id].is_blank? ? nil : params[:id].to_i # ä¸ã®ãããªã³ã¼ããé »ç¹ã«åºã¦ããã®ã§ãStringã¨Nilã¯ã©ã¹ã« # to_id ã¨ããã¡ã½ãããå®ç¾©ãã以ä¸ã®ããã«æ¸ããããã«ãã¾ãã id = params[:id].to_id
å®ç¾©ã¯
module CoreExtentionsForString def to_id self.blank? ? nil : self.to_i end end module CoreExtentionsForNilClass def to_id nil end end NilClass.send(:include, CoreExtentionsForNilClass) String.send(:include, CoreExtentionsForString)
2. RSpecã§ãã¹ããæ¸ã
RSpecã§(ã¹ããã¯)ãã¹ããæ¸ãã¾ããã ä»åã
- ãã¸ãã¯ã¯ã¢ãã«ã«éç´ããã³ã³ããã©ã¼ã«ã¯ãã¸ãã¯ã¯æ¸ããªã
- ãããã£ã¦ããã¹ãã¯ã¢ãã«ä¸å¿
- æ±ãã³ã¼ãã¯ãã¹ããåºæ¥ãããªãã¡ã¯ã¿ãªã³ã°ãã
- ãã¹ãã¯å¾ä»ã§ãè¯ããã絶対ã«æ¸ã
ã¨ããæ¹éã§RSpecãæ¸ãã¾ããããã®ããã¸ã§ã¯ããåRSpecã ã£ãã®ã§ããªãã¨ãã¹ããç´3400è¡ã¨å¦çã®ã³ã¼ãã¨åããããã®è¡æ°ãããã¾ãããããæ¸ãéãããããã¾ãã ^^);
ãããã§ãããã¸ã§ã¯ãéä¸ã§ã®ãã¼ãã«æ§é 大å¤æ´ã Ruby on Railsã®ãã¼ã¸ã§ã³ã¢ãããé£ãªãä¹ãåãã¾ããã
3. ãããã¿ã¤ã
ä»åã®ä»äºã®ã客æ§ã¯ãITã«è©³ããã¯ããã¾ããã§ãããã¾ããåãã¦ã®æ¥ç¨®ã ã£ãã®ã§ç§ããªããªãã客æ§ã®è©±ã¦ããå 容ãç解ã§ãã¾ããã§ãããããã§ãRailsã®ç¹æ§ãæ´»ãããããã¿ã¤ããä½ããã客æ§ã¨ä»æ§ã®æåãããã¾ãããçµå±ï¼åããã¿ã¤ããä½ãã¾ããã
æåã®ããã¿ã¤ãã¯ãã客æ§ã®ããããäºãç§ãç解åºæ¥ã¦ããã®ãã確èªããã®ãä¸çªã®ç®çã«ãªãã¾ããããã®æ®µéã§ç§ã®ç解ãééã£ã¦ããã¨ç¢ºå®ã«ãã客æ§ã®æã¿ã¨ã¯éããã®ãä½ã£ã¦ãã¾ãã¾ãã
æ¬è³ªçã ã¨æãé¨åã®ã¿ã Scaffoldçã使ã£ã¦ãµã¯ãµã¯ã¨ä½ã£ã¦ã¿ã¾ãããã»ã»ã»ã»ã»ã»ã¨ããã®ã¯åã§JQueryã§åã£ãUIãä½ãã®ã«æéã使ã£ã¦ãã¾ã ^^); éä¸ãã Scaffoldã§ä½ã£ãã·ã³ãã«ãªç»é¢ã¸ã¨æ¹å転æãã¾ããã
2çªç®ã®ãããã¿ã¤ãã¯æåã®ãããã¿ã¤ãã§(æéã®é½åã§)ä½ã£ããªãã£ãæ©è½ãå ããããæåã®ãããã¿ã¤ãã«ã対ããè¦æãå ãããããã¿ã¤ãã§ããã®æ®µéã§ã»ã¼ä»æ§ã¯ç¢ºå®ãã¾ããã
3çªç®ã®ãããã¿ã¤ãã¯ãç´å ¥ããã·ã¹ãã ã®ä»æ§ç¢ºèªã¨ããä½ç½®ã¥ãã§ããã
ãããã¿ã¤ããä½ãã客æ§ã¨æåãããæ¹æ³ã¯ã
- ã客æ§ãã·ã¹ãã ã«è¦æ±ã»æå¾ ãã¦ãããã¨ãå ·ä½çã«åºã¦ããã®ã§ãééã£ãæ¹åã®ã·ã¹ãã ãä½ããã«ãã
- ã客æ§ã«åºæ¥ã¦ããã·ã¹ãã ã®ã¤ã¡ã¼ã¸ãä¸ããäºãåºæ¥ãã客æ§ã«å®å¿æãä¸ãã
- å°å ¥æãããã¿ã¤ãã§ç¥ã£ã¦ããã·ã¹ãã ãªã®ã§ãã©ãã«ãçºçããªã
çã®è¯ããã¨ã ããã ã¨æãã¾ããåé¡ã¯ãããã¿ã¤ããä½ãå·¥æ°ã§ãããRuby on Railsãªãããããã ãããã¶ã§ã ^^)
ã¾ã以åæ¸ãã オレオレscaffold generator を作る ã®ããã«Scaffoldã®ä½ãã³ã¼ããã«ã¹ã¿ãã¤ãºããäºã§åããããªç»é¢ãéç£ã§ããã®ãRailsã®å¼·ã¿ã§ãã
ã¾ã¨ã
Ruby on Railsã使ãã¨ããããã¿ã¤ãã使ã£ãéçºãã§ããã客æ§ã®æºè¶³åº¦ã®é«ãã·ã¹ãã ãä½ãäºãã§ãã¾ãã
ãã ããRuby on Railsã§é«ãçç£æ§ãåºãã«ã¯ãRuby on Railsã®ãã¼ã¹ã§ãããªãã¸ã§ã¯ãæåãã¢ã¸ã£ã¤ã«éçºãã¡ã¿ããã°ã©ãã³ã°çã®ç¥èããããªãã«å¿
è¦ã«ãªãã¾ãã
ã¾ããç©æ¥µçã«è±èªãã½ã¼ã¹ã³ã¼ãããæ
å ±ãåéãã姿å¢ãéè¦ã ã¨æãã¾ãã