è¨ãä¸ãã£ãã¢ãã«ããæ©è½ãåé¢ããåãå£
Railsã®ã¢ãã«ã«ã¡ãã³ã¡ãã³ã¨å¦çã追å ãã¦ããã¨ããã¤ã®éã«ããµã¤ãºãè¨ãä¸ãã£ã¦ãã¾ã£ã¦ãããããã
Railsã§ãã¸ãã¯ãæ¸ãå ´æã¨ãã¦ä¸ãããã¦ããå ´æã¯ã³ã³ããã¼ã©ãã¢ãã«ãªã®ã§ããã³ã³ããã¼ã©ã¯åç´ã«ããªãããã¨ããæãã«å¾ãã¨ãå¿ ç¶çã«å¤ãã®å¦çã¯ã¢ãã«ã«æ¸ããã¨ã«ãªã£ã¦ãã¾ããã¢ãã«ãè¨ãä¸ããçµæã«é¥ããããã
ããã解æ¶ããããã«ãã¢ãã«ããåãåºãããã®ã¯åãåºãã¾ããããã¨ãããã¨ã§ãä¸è¨ã®è¨äºã«ãè¨ãä¸ãã£ãã¢ãã«ããæ©è½ãå¥ã®ç¬ç«ããã¯ã©ã¹ã«åãåºãããã®ï¼ã¤ã®åãå£ãæ示ããã¦ããã
http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/
以ä¸ã¯ãã®ã¡ã¢ã
ããªã¥ã¼ãªãã¸ã§ã¯ã
ä¸ã®è¨äºã§ã¯ä¾ã¨ãã¦ãcostã¨ããæ°å¤ãã£ã¼ã«ããRatingã¨ããããªã¥ã¼ãªãã¸ã§ã¯ãã§åãæ±ã£ã¦ããã Ratingã¯costã§åæåãããAããFã®æå表ç¾ã«å¤æãããã Ratingã«ã¯Ratingå¤ã©ããã®å¤§å°ãæ¯è¼ããæ¼ç®åãå®ç¾©ãããã
ãµã¼ãã¹ãªãã¸ã§ã¯ã
è¤éãªå¦çãè¤æ°ã®ã¢ãã«ã«ã¾ãããå¦çãå¤é¨ãµã¼ãã¹ã¸ã®ã¢ã¯ã»ã¹ãªã©ãã©ããããã
ãã©ã¼ã ãªãã¸ã§ã¯ã
è¤æ°ã®ã¢ãã«ãä¸ã¤ã®ãã©ã¼ã ã§æ´æ°ããã®ã«ä½¿ãã nested_attributesã使ããããã¹ãããªããã
ã¯ã¨ãªã¼ãªãã¸ã§ã¯ã
è¤éãªã¯ã¨ãªã¼ã§ActiveRecordã®ãµãã¯ã©ã¹ãscopeãã¯ã©ã¹ã¡ã½ããã ããã«ãªã£ãããããããã¯ã©ã¹ã¨ãã¦åé¢ããã
ãã¥ã¼ãªãã¸ã§ã¯ã
ç»é¢è¡¨ç¤ºç¨ã®ã¿ã«ãã¼ã¿ãå å·¥ããå¿ è¦ãããã¨ãã¯ãã¢ãã«ã«ãã¸ãã¯ã追å ããã®ã§ã¯ãªãããã¥ã¼ãªãã¸ã§ã¯ãã¨ãã¦ç¬ç«ããã¯ã©ã¹ã«åãåºãã ããã·ã¥ãã¼ããã¼ã¸ãªã©ããã
ããªã·ã¼ãªãã¸ã§ã¯ã
ã¢ãã«ã®è¤æ°ã®ãã£ã¼ã«ãã®å¤ãçµã¿åããã¦1ã©ã³ã¯æ½è±¡åº¦ã®é«ãç¶æ ã表ããããªå ´åã«ãç¬ç«ããã¯ã©ã¹ã§ããã表ç¾ããã ãµã¼ãã¹ãªãã¸ã§ã¯ããæ´æ°ç³»ã®å¦çã§ããã¡ãã¯èªã¿åãç¨ã®ãªãã¸ã§ã¯ãã
ãã³ã¬ã¼ã¿
ã¢ãã«ã®æä½ã®åå¾ã«å¦çã追å ããã ã³ã¼ã«ããã¯ã¨åãç®çã ããããããå¦çãæ¯åã¯å¿ è¦ã§ã¯ãªãå ´åããã¢ãã«ã«å½¹å²ãæãããããã®ãé¿ãããå ´åãªã©ã«ã ä¾ã¨ãã¦ã¯ãå¦çã®å®è¡å¾ã«SNSã«æ稿ããå¦çãä»ã足ãã¨ãã£ããã¨ã