ð Railsãã¥ãŒããªã¢ã«è§£èª¬åç»ã®èŠæãŸãšã
Railsãã¥ãŒããªã¢ã«è§£èª¬åç»ã¯çŽ36æé以äžã®å€§ããªã¥ãŒã ãšãªã£ãŠãããïŒåšçµãã£ãŠããããïŒåšç®ãïŒåšç®ãšããæ¹ããä»èšèªããåŠã°ããŠããæ¹ã«ã圹ç«ã€æ å ±ããããããããŸããåç»ã¯ææ¥åœ¢åŒã«ãªã£ãŠãããäœåºŠãç¹°ãè¿ãèŠãããšãå¯èœã§ããããã¹ãçã®äºç¿ã»åŸ©ç¿ã«ãèªå奜ã¿ã®äœ¿ãæ¹ã§ç解ãæ·±ããã®ã«ãã£ãšåœ¹ç«ã€ã¯ãã§ãã
æ¬èšäºã¯ç¬¬4ç (Rails 5.1 察å¿) ã®çŽ¹ä»èšäºã§ãã第6ç (Rails 6.0 察å¿) ã®èŠæã«ã€ããŠã¯2020幎12æã®èšäºããåç §ãã ãã â
ãã¡ããå§ãããå šãŠãèŠãŠãããã®ãäžçªãªã®ã§ããããŸãã¯ãã®äžã§ ãããããã®è§£èª¬ç®æããå³éžããŠã¿ãã®ã§ã30åã®ç¡æèŠèŽãæå¹ã«äœ¿ã£ãŠããã ãã®ã«ãè¯ããã°åèã«ããŠã¿ãŠãã ããã
ç®æ¬¡
第ïŒç« ã第ïŒç«
- Railsã£ãŠäœã ããïŒ
- Railsãã¥ãŒããªã¢ã«ãå§ãã
- Gitãåãããããã€ã¡ãŒãžãã
- MVCãç解ãã
- ãã¹ãäœã®ããã«ããã®ïŒ
第ïŒç« ã第ïŒç«
第ïŒç« ã第ïŒç«
- Sessions ã«ã€ããŠç¥ã
- Helper ã¯ãããã£ãŠäœ¿ã
- Rubyã&&ããšã¯ïŒ
- Ruby èªå·±ä»£å ¥æŒç®å
- ã¯ã©ã¹ or ã€ã³ã¹ã¿ã³ã¹ã¡ãœããïŒ
- Cookies ã䜿ã£ãèªèšŒã®ä»çµã¿
- Ruby è€é㪠if æ
- ãã¹ãã§æŽ»èº ãraiseã
- private ã¡ãœãã ãšã¯ïŒ
第ïŒïŒç«
- HTTPãªã¯ãšã¹ã patch ãš delete
- before ãã£ã«ã¿ãŒã«ã€ããŠ
- ãã¬ã³ããªãŒãã©ã¯ãŒãã£ã³ã°
- ïŒæ®µéã®ãªãã¡ã¯ã¿ãªã³ã°
- Ruby ã®ã!ããš Rails ã®ã!ãã¯å¥ç©
第ïŒïŒç« ã第ïŒïŒç«
- ã¡ãŒã«èªèšŒã®ä»çµã¿
- create ãš save ã®éã
- ã¡ã¿ããã°ã©ãã³ã°ã«è§Šãã
- ãã¹ãã§äŸ¿å©ãªãassignsã
- beforeãã£ã«ã¿ãŒã§ãªãã¡ã¯ã¿ãªã³ã°
- Ruby ãäžçå·ã䜿ã£ãæéãã®èªã¿æ¹
第ïŒïŒç«
- DBèšèšïŒã¢ããªã³ã°ïŒãäœéšãã
- Rubyã->ããã®ç¢å°ã¯äœã ïŒ
- 芪ã¯ã©ã¹ãžç§»åããããªãã¡ã¯ã¿ãªã³ã°
- ããŒã·ã£ã«ã®ãšã©ãŒã¡ãã»ãŒãžã䜿ãåã
- äžã€åã®URLãè¿ã request.referrer
- accept ã§ããã³ãåŽã«ãããªããŒã·ã§ã³
第ïŒïŒç«
- ãã©ããŒ&ãã©ãã¯ãŒã®ã¢ãã«èšèš
- resourcesã®æ°ããªäœ¿ãæ¹
- ç°ãªãã¢ã¯ã·ã§ã³ãïŒã€ã®ãã¥ãŒã§å®è£
- Ajax 㧠Follow ãã¿ã³ãå®è£ ãã
- SQL ã«è§Šãã
æåŸã«
Railsã£ãŠäœã ããïŒ
èªåãä»ããåŠã¶ãã®ãäžã®äžã§ã¯ã©ã®ããã«å©çšãããŠããã®ããã©ããªç¹åŸŽãããããç¥ã£ãŠããã®ã¯å€§äºãªããšã ãšæããŸããããããRailsãšã¯ã©ããããã®ãªãã ããïŒ Railsã䜿ã£ãŠã©ããªãµãŒãã¹ãäœããããã«ãªãã®ã ããïŒãšããçåãæ±ããŠããæ¹ã«æ¯éèŠãŠãããããã®ããã第ïŒç« åŸç·š ïŒïŒ.ãªãã±ãã®éšåã§ãã
Railsãå©çšããäžã§ãç¥ã£ãŠãããã»ããããããšãã®ã¥ããšè©°ãŸã£ãŠããã®ã§ãããããRailsãåŠã¶ãšããæ¹ã«æ¯éç¥ã£ãŠãããŠæ¬²ãããšããã§ãã
ðŒRailsã䜿ãããªããããã«ãªãã«ã¯ãRailsãã¥ãŒããªã¢ã«ïŒé±ããçšåºŠã§ã¯çšé ããããšããã®ãåããå³ãæ§ã ãªããŒã¿ãšæ¯èŒããŠããŠé¢çœããã奥ãæ·±ãã§ãã
Railsãã¥ãŒããªã¢ã«ãå§ãã
ä»ååããŠRailsãã¥ãŒããªã¢ã«ã«ææŠãããšããæ¹ã«çµ¶å¯ŸèŠãŠæ¬²ãããšæããšããã ã第ïŒç« åç·š Railsãã¥ãŒããªã¢ã«ã®é²ãæ¹ãã§ããç¹ã«ãïŒ. åæç¥è ããèŠãŠãããšãä»åŸã®Railsãã¥ãŒããªã¢ã«åŠç¿ã«åœ¹ç«ã€ããšãããããåºãŠããŸãã
åå¿è ã«åããŠå¿æ§ãããã¢ãããŒã·ã§ã³ãä¿ã€çºã®æ¹æ³ãªã©ãããããã®åŠç¿æ¹æ³ã®åèã«ãªã話ã¯èå³æ·±ãã§ããRuby / Rails ã®æ§é ã«ã€ããŠãå匷ã«ãªããŸãããrbenvãã䜿ãããªããïŒ
Gitãåãããããã€ã¡ãŒãžãã
Railsãã¥ãŒããªã¢ã«ãé²ããäžã§ ã Git ãã«ã€ãŸã¥ãæ¹ã¯ããªãå€ããšæããŸãããã®ãGitãã«ã€ããŠäžå¯§ã«èª¬æãããŠããã®ã ã第ïŒç« åŸç·š ïŒ. Git ã«ããããŒãžã§ã³ç®¡çãã§ããã²ãŒã ã®ã»ãŒãæ©èœã«äŸããŠåããããã説æãããŠããŸãã
åããŠã ãšããåãããªãéšåãïŒè¡ãã€äžå¯§ã«æããŠãããŸãã
å®éã«å®å·ããã®æäœããã¿ãŒããã«ãèŠãªããåŠç¿ã§ããã®ã§ããšãŠãåãããããã§ããæåãªGitHubãªã©ã®èª¬æããããŸãããã®æµãã§ãHerokuãã«ã€ããŠã®è§£èª¬ãããã®ã§ãæ¬çªç°å¢ã«ã€ããŠã¹ã ãŒãºã«ç解ã§ããããã«ãªã£ãŠããŸããïŒæ¬çªç°å¢ã«ãããããã®ãGitããªãã§ããâŠïŒïŒ
MVCãç解ãã
ãMVCãã®æµããç解ãããæ¹ã¯ ã第ïŒç« åç·š ïŒïŒ. MVCã®æåã«è§ŠããŠã¿ãããèŠãŠã¿ãŸãããã
MVC å šäœã®æµããã¹ã©ã€ãä»ãã§èª¬æããŠãããŠãRails ã«ãŒãã£ã³ã°ã«ã€ããŠã®å šäœåã«ã€ããŠãåãããŸãããã®äžéãã®æµããrailsãã¥ãŒããªã¢ã«ã§å°ããã€ãã£ãŠããã®ã§ãåããŠã®æ¹ã¯ãã®å šãŠãä»ã®æ®µéã§ã¯ç解ããŠããªããŠã倧äžå€«ã§ããMVCã®å šäœåãç解ãããæ¹ããRailsã«ã€ããŠãã£ãšåŸ©ç¿ãããæ¹ã«ããããã§ãã
ãã¹ãäœã®ããã«ããã®ïŒ
ãã¹ããªããŠäžäººã§å匷ããŠããšäœ¿ãå Žé¢ã¯ããŸãåºãŠããªããããããããã¹ãã£ãŠå¿ èŠãªã®ïŒãšãæãã®æ¹ã¯ ã第ïŒç« åŸç·š ïŒïŒ. TDDã®çŽ¹ä»ãšãŸãšããããã®è©±ãäžåºŠèããŠã¿ããšè¯ããšæããŸãã
ãã¹ãã¯å ã«æžãã¹ãïŒåŸãããã®ïŒãªã©ãåããããã解説ãããŠããŸãã
ããããRailsã䜿ã£ãŠãä»äºããããïŒãšããæ¹ã¯ããã¹ããã¯å¿ é ã«ãªãç¥èã ãšæãã®ã§èŠãã§ãã¯ã®ç®æã§ãã
Rubyã«ã€ããŠç¥ã
Rubyã£ãŠä»ã®èšèªãšã©ãéãã®ã ããïŒ Rubyã®ç¹åŸŽãç¥ã£ãŠäžæã«äœ¿ãããªããããšããæ¹ã«ã¯ ã第ïŒç« åç·š ïŒ. Rubyã®ç¹åŸŽãããèŠãã®ãããããã§ãã
å®å·ããã®èª¬æã ãšã³ãŒãããæ¬äººåããããŠããŠé¢çœãã®ã§ãããã¹ãã ãã ãšç ããªã£ãŠããŸããããªè©±ã§ãé ã«ãã£ãšå ¥ã£ãŠããŸããPythonãšã®ç¹åŸŽã®éãã®è©±ãåèã«ãªããŸãããRuby ã¯äººéã«å¯ãæ·»ã£ãèªç±ãªèšèªã ãªãšæããŸãããæŽã«æ·±ã説æãããã®ã ã第ïŒç« åŸç·šãã§ãã
åŠçé床ãèšç®ããŠæ¯ã¹ãããçµæ§æ·±ãRubyã«ã€ããŠç¥ãããšãã§ããã®ã§ãäœãšãªãããç解ããŠããªãã£ãéšåãè ã«èœã¡ããããããªãã§ããã
ããŒã¿ããŒã¹ãç解ãã
ããŒã¿ããŒã¹ã¯ãããããã®ç« ãç解ããŠããã®ã«éåžžã«å€§åãªéšåãªã®ã§ ãïŒç« åç·š ïŒ. Userã¢ãã«ãçæããããããéäžã§ããæã«ãã£ããèŠããšè¯ãã§ãããã€ã°ã¬ãŒã·ã§ã³ãã¡ã€ã«ã®æ±ãæ¹ãªã©ã«ã€ããŠã詳ãã説æããããŸãã
説æãèããšãActive Record ã䜿ããšããŒã¿ããŒã¹ãšã®ãããšããããããªã«æ¥œã«ãªããã ïŒãšããããšãåãããŸãã
èå³æ·±ãã®ãããïŒç« åŸç·š ïŒ. äžææ§ã®åé¡ ãã®ãšããã§ãããŠãŒã¶ãŒãåæã«ç»é²ãããªãããã«åé¿ãããæ¹æ³ã®èª¬æã¯éåžžã«å匷ã«ãªããŸãã
ãã¹ã¯ãŒãã®æ±ãæ¹ã®ãäœæ³ãåŠã¹ãŸãã䟿å©ãªãã®ããããããã Rails åãã§ãããããã§ã¯ããæ£èŠè¡šçŸãã«ã觊ããããŸããåããŠã®æ¹ã«ã¯é£ããæããããéšåã ãšæããŸãããåç»ãèŠãªãããªããšãªãã§ãç解åºæ¥ããšå¬ããã§ããã
å€æ°ã®çš®é¡
ããŒã«ã«å€æ°ãšã€ã³ã¹ã¿ã³ã¹å€æ°ã®éããäŸãã°ãuser
ãš @user
ã®éããçããåãããŸããïŒãããèŠäºã«è§£æ±ºããŠãããã®ã ãïŒç« åç·š ïŒïŒ. å€æ°ãå®çŸ©ãããã ã§ãã
çã説æã§åããããããå€æ°ã®ãšããã¯30å以å ã§èããŸãã
ïŒç« ã§ã¯ HTTP ãªã¯ãšã¹ãã«ã€ããŠããifæã®äœ¿ãåãïŒå眮ã»åŸçœ®ïŒããããã¯ã®äœ¿ãæ¹ãRESTful ã«ã³ãŒããäœããã€ã³ãããã®ã¡ãªãããªã©ãå匷ã«ãªãããšãçãã ãããã§ããèªåã®æ°ã«ãªããšãããããã°æ¯éãèŠããŠã¿ãŠäžããã
form_for ã®äžèº«
Railsã¯è²ã 䟿å©ãªã®ã§ãããformã®äžèº«ã¯ã¡ãããšHTMLã§ç解ããããšã倧äºã§ããform_for ã®äžèº«ã®ç¢ºèªæ¹æ³ãåãã ãïŒç« åŸå ïŒ. ãšã©ãŒã¡ãã»ãŒãžã衚瀺 ãã®åŸåéšåïŒ44:50ãïŒãåèã«ãªããŸãã
ãã£ãããããŒããŒã«ã䜿ã£ãŠHTMLåãããã®ãèŠãªãããåãããªããã®ã¯æŽã«èª¿ã¹ããããŠã¿ããšããªãç解ãæ·±ãŸããšæããŸããRailsã§æžãããã®ããã©ã®ããã«HTMLã«å€æãããã®ããåãããšå¬ããã§ããã
Sessions ã«ã€ããŠç¥ã
Sessions ãé£ããæããæ¹ãå€ããšæããŸãããïŒç« åç·š ïŒ. Sessions ãªãœãŒã¹ã«ã€ããŠãã§è©³ããèŠãŠã¿ãŸãããã
ãã°ã€ã³ãããã°ã¢ãŠãã¯é »ç¹ã«è¡ãããããšãªã®ã§ãæ¯åããŒã¿ããŒã¹ã«ã¢ã¯ã»ã¹ãããããããæ¹æ³ã¯ããããâŠð€ãšãããšããããã®è©±ãçŽåŸã§ããŸãããããåããã°ãSessionsãã«ã€ããŠèª¬æã§ããããã«ãªããŸããã
ãŸã ãïŒç« ïŒ. ã»ãã·ã§ã³æå¹æéããããïŒ. æ»ææå£ã®çŽ¹ä»ãã®èª¬æãçããŠåãããããã®ã§ããããã§ãããµãŒãã¹ããšã«é©åãªæéãèšããŠããªããã°ãªããªãããšããã©ã®ãããªæ»æã®æå£ãããã®ãå匷ã«ãªããŸãã
Helper ã¯ãããã£ãŠäœ¿ã
ãïŒç« åç·š ïŒïŒ. ã³ã³ãããŒã©ã§ãã«ããŒã䜿ã ã1:20:08ããèŠããšãHelper ã«ã€ããŠã®èª¬æãçããŸãšãŸã£ãŠããŸãã
解説åç»å ã§ã¯ãã¹ã ãŒãºã«ãšã©ãŒãªããããªãé²ãã§ããã ãããšããèš³ã§ã¯ãããŸãããå®éã«ãšã©ãŒç»é¢ãåºãŠããŠãããããå®å·ããã解決ããŠããã®ãèŠãŠããã®ãçµæ§å匷ã«ãªããŸããããã§ã¯ãHelper ãããŸãèªã¿èŸŒãŸããŠããªãã£ãã®ã§ãããã解決ããªããã®å®è£ ã§ãã
ïŒããŸãïŒ
ãã®åŸãBootstrap ã®JavaScript ãããŸãåããªãããšãããã©ãã«ã«èŠèãããŸãããã次ã®ïŒç« åŸç·šã®åé ã§ã¡ãããšè§£æ±ºãããŠãã®ã§ãå®å¿ãâŠïŒ(ã©ã解決ãããããããŸãå匷ã«ãªããŸãã)
Rubyã&&ããšã¯ïŒ
ããã°ã©ãã³ã°ã£ãŠããšããããåãåãã«ããã ããªãäœéããæžãæ¹ããããŸãããRubyã ãšãifãæããããªã«ã·ã³ãã«ã«æžãã¡ãããããšé¢å¿ãããããã®ã ãïŒç« åç·š ïŒ. ãŠãŒã¶ãŒã®æ€çŽ¢ãšèªèšŒã32:25ã ããã®èª¬æã§ãã
ðŒçµæ§é£ãããã¯ããã¯ã䜿ãããŠããã³ãŒããªã®ã§ãã
äžããåã¿ç ããŠèª¬æããŠãããã®ã§ãããã¹ãã ãããåãããªããªâŠãšããæ¹ã¯ãäžåºŠèŠãŠã¿ããšè¯ãããã§ãã
Ruby èªå·±ä»£å ¥æŒç®å
ãã®èšå·ã䜿ã£ãã³ãŒãããæžæãæ¹ã¯å€ããšæããŸãããããäžå¯§ã«å解ããŠèª¬æããŠãããã®ã ãïŒç« åç·š ïŒ. session ã®äœ¿ãæ¹ãã®çµãã 1:05:36ã ããã§ãã
ããã¯å ã»ã©äžã§çŽ¹ä»ããRubyã&&ããšã¯ïŒãç¥ã£ãŠãããšããåããããããšæãã®ã§ããã¡ããšåãããŠèŠããŠã¿ããšããããšæããŸããããããèšæ³ãååŸã§ãããšãã³ã³ãã¥ãŒã¿ã«ç¡é§ãªåŠçããããªããäžæ©é²ãã ããã°ã©ãã³ã°ãã§ãããã§ããã
ã¯ã©ã¹ or ã€ã³ã¹ã¿ã³ã¹ã¡ãœããïŒ
解説åç»ã«ã¯ãåç« ã®çµããïŒãŸãã¯å®å·ãããèšããã»ããè¯ããšæãããç®æïŒã«è³ªåã³ãŒããŒããããåç»å ã®çåŸãããè¯ã質åãæããããŠãããŸãããã㯠Web ããã¹ãçã«ã¯ç¡ãå 容ã§ãåç»ãèŠãªããšç¥ããªãæ§ã ãªè§£èª¬ããããŸãã
ãïŒç« åŸç·š ïŒ. 質åã³ãŒããŒãã§ã¯ãã¡ãœããã®çš®é¡ã«ã€ããŠãçåŸããããã®åçã«çããªããåããããã説æããããŸãã
äœæ°ãªã䜿ã£ãŠããã¡ãœããããããããã®ãã€ã³ã¹ã¿ã³ã¹ïŒãŸãã¯ã¯ã©ã¹ïŒã¡ãœããã ã£ãã®ãããšæ°ä»ãããããšæããŸãããªããšãªãã§äœ¿ã£ãŠããããããã¡ãããšç解ããŠäœ¿ãããšå¬ãããªããŸããã
Cookies ã䜿ã£ãèªèšŒã®ä»çµã¿
Cookie ãå©çšããŠèªèšŒãè¡ãã®ã¯çµæ§è€éãªå 容ã«ãªã£ãŠããŠãç解ã«èŠããæ¹ãå€ããšæããŸãããïŒç« ïŒ. ãã°ã€ã³ç¶æ ã®ä¿æããèŠãŠããããšãã»ãã·ã§ã³ãšã¯ãããŒã®éãã«ã€ããŠåããããã説æãããŠããŸãã
ðŒãã®ãRemember meãã®éšåã§ããããã°ã€ã³ç¶æ ãã©ã®ããã«ä¿æããã®ãïŒãšãããšããã§ãã
ãã°ã€ã³ç¶æ
ã®ä¿æãããã«ã¯ ãä»®æ³çã«ã©ã ããšãããã®ãèªåã§å®è£
ããŠãããªããã°ãªããŸããããã®äžèº«ãç¥ããã®ãã25:09ãããã®èª¬æã§ããäžæçã«ä¿åã¯ãããã©ããŒã¿ããŒã¹ã«ã¯åæ ãããªãä»çµã¿ãäœããã§ãããRubyã®æ©èœã§ãã®ã»ãã㯠attr_accessor
ãšãããã®ã§çšæãããŠãããã ãïŒãšãã説æã§ãã䟿å©ã§ã³ã£ããã§ããã
ïŒç« ã®äžã§ãç¹ã«ãã£ããç解ããã¹ãã ãšæããã®ã¯ ã ïŒ. ãã°ã€ã³ç¶æ ã®èªèšŒãã§ãã
ãã®èªèšŒã®æµãã¯ãã®å ãäœåºŠãåºãŠããã®ã§ããããç解ã§ããã®ãšã§ããªãã®ãšã§ã¯ãä»åŸå€§ããªå·®ãçãŸããŠããã¯ãã§ããäœåºŠãç解ã§ãããŸã§ç¹°ãè¿ãèŠããšå¹æçã ãšæããŸãã
Ruby è€é㪠if æ
cookieã䜿ã£ãèªèšŒã«ãããcurrent_user ã¡ãœãããå€åãããå Žé¢ã§ãã
if (user_id = session[:user_id])
ãããæ¯èŒã§ã¯ãªãä»£å ¥ãšèšãããŠãããååŠè ã«ã¯çŽããããã§ããâŠ><ããã㧠ãïŒç« ïŒ. ããäžåºŠãã°ã€ã³ãèŠæ±ãããããèŠãŠã¿ãŸãããã
现ããå解ããŠã詳ãã説æããŠãããã®ã§ãšãŠãå©ãããŸãã
ãã¹ãã§æŽ»èº ãraiseã
ã©ããããã® raise
ãšãããã®ã¯ããã¹ãã®æã«äŸ¿å©ãªãã¯ããã¯ãããã§ããããã詳ãã解説ããŠããã®ã ãïŒç« ïŒïŒ. raise ãå
¥ãããã¯ããã¯ãã§ãã
raiseãã¯åçç¡çšã§ãããã®ãçºçãããã³ãŒãã®ããã§ããã
ðŒraise ãå€ããšã©ããªãã®ãâŠïŒããå ·äœçã«ã©ããã£ãŠäœ¿ãã®ãåããããã解説ãããŠããŸãããã話ãèããŠãããš raise ã䜿ããªããŠãæ€ç¥ããŠããã䟿å©ãªãµãŒãã¹ãããâŠïŒïŒãããã£ã話ãå匷ã«ãªããšæããŸãããã¹ãç¶²çŸ çã«ã€ããŠã®è©±ãèå³æ·±ãã§ãã
private ã¡ãœãã ãšã¯ïŒ
ã³ã³ãããŒã©å
ã§èŠããã private
ãšãã宣èšããããã€ãããšäœãèµ·ããã®ãïŒãšããçåã«çããºãããšçããŠãããŠãããšããã ãïŒïŒç« åç·š ïŒ. private ã¡ãœããã«ã€ããŠãã§ãã
ãããæžããªããŠããšã©ãŒã«ã¯ãªããªããããã©ãæžãããã®çç±ãããã§ç¥ãããšæããŸãã3åã»ã©ã®èª¬æã§çŽåŸã§ãã説æãèããã®ã§ããããã§ãã
ãïŒïŒç« åç·š ïŒ. before_action ã«ã€ã㊠ã1:01:30ãããã private ã䜿ããšãã®ãã€ã³ãã«ã€ããŠèª¬æããããŸãã
ãã¡ããçãæéã§èããã®ã§ããã²ã芧ãã ããã
HTTPãªã¯ãšã¹ã patch ãš delete
edit ã§äœ¿ããã©ãŒã ã¯ãïŒç« ã§ãã£ããç»é²ãã©ãŒã ããšã»ãŒåãã§ããéããšããã¯ãHTMLã® form ã¿ã°å ã«ããã¡ãœããããããè²ã ãšäžæè°ãªããšããããŸããããã詳ãã説æããŠãããŠããã®ã ãïŒïŒç« åç·š ïŒ. HTMLãšHTML ãã§ãã
ãããïŒåã»ã©ã§èããçã説æãªã®ã§ãHTTPãªã¯ãšã¹ãã«ã€ããŠå匷ããããšããªãæ¹ã¯ç¹ã«èããŠã¿ããšãããšæããŸããpatch
ã¡ãœããããdelete
ã¡ãœããã«ã€ããŠãHTTPãªã¯ãšã¹ãã®æŽå²ãã説æãããŠããã®ã§ãåãããšæ¥œãããšããã ãšæããŸããWeb ã®æŽå²ã«èå³ã湧ããŠããããæŽã«èªåã§èª¿ã¹ãŠã¿ããšæ¥œãããã§ããðãã©ãŠã¶ã®æŽå²ãªã©ã調ã¹ãŠã¿ããšé¢çœããã§ãã
before ãã£ã«ã¿ãŒã«ã€ããŠ
ãã°ã€ã³ããŠããªãã®ã«ãä»ã®äººã®æ å ±ãç·šéã§ãã¡ãããã㪠Web ãµãŒãã¹ã¯å±éºã§ããããã¡ãããšããã°ã€ã³ãããŠããæ¬äººã®æ å ±ã ããç·šéã§ããããã«å®è£ ããªããã°ãããŸããããïŒïŒç« åç·š ïŒ. èªå¯ã«ã€ã㊠ãã§ã¯ beforeãã£ã«ã¿ãŒããããŠãã®å±éºããå®ã£ãŠãããæ¹æ³ãåããããã解説ãããŠããŸãã
ã¡ãœãããåŒã³åºããšãã®æžãæ¹ã®ãã€ã³ããããªã Ruby ã§ã¯ãã¹ããŒã¯ã±ãŒã¹ãïŒã¢ã³ããŒããŒã䜿çšããæžãæ¹ïŒã䜿ãããšãæ £ç¿ãšãããŠããã®ããªã©ã®è±ç¥èãå«ãŸããŠããŠãå匷ã«ãªããŸãã
ããã« ãïŒïŒ. æ£ãããŠãŒã¶ãŒã確èªããã1:14:00ã ã§ã¯ãbefore ã¢ã¯ã·ã§ã³ãæžãé çªã«ã€ããŠã®è§£èª¬ãããã®ã§ããããåãããŠãã§ãã¯ããŠã¿ããšè¯ããšæããŸãã
before_action ãå®è¡ãããé çªãç解ãããšããªããã®ã³ãŒãã§ããã®ãïŒãæ確ã«åããããã«ãªããšæããŸãã
ãã¬ã³ããªãŒãã©ã¯ãŒãã£ã³ã°
ïŒïŒç« ã®ãã®éšåã§ãã
ããã¹ãã ãã ãšåããããããããããªãã®ã§ãããããæã ãåç»ã§èŠãŠãããšããã®ãæå¹ãªäœ¿ãæ¹ãããããªãã§ããããïŒïŒç« åç·š ïŒïŒ. æ£ãããŠãŒã¶ãŒã確èªããã1:19:00ã ã«ãåçŸããåç»ããããŸãã
åç»ã§èŠããšãåããšããããŠãŒã¶ãŒããã«ã¯ãªãã¯ãããã®ã¯äžèŠªåã ãšããäºãæèŠçã«åãããããç解ã§ãããšæããŸãããããããŠãŒã¶ãŒãé æ ®ãã现ããå®è£ ã¯ããªãªãžãã«ã¢ããªãéçºããæ¹ã«ãåèã«ãªãããã§ããã
ïŒæ®µéã®ãªãã¡ã¯ã¿ãªã³ã°
ãŠãŒã¶ãŒã®äžèŠ§è¡šç€ºãããã¥ãŒã®ãªãã¡ã¯ã¿ãªã³ã°ã§ãã
<%= render @users %>
ãã£ãããã ãã§ãŠãŒã¶ãŒãäžèŠ§è¡šç€ºãããŠããã®ã§ãããå®ã«ã·ã³ãã«ã§ãâŠããªããããªã·ã³ãã«ã«æžããã®ãïŒããã¡ããšç解ããªããšæ··ä¹±ããŠããŸãéšåã ãšæãã®ã§ ãïŒïŒç« åŸç·š ïŒ. ãªãã¡ã¯ã¿ãªã³ã°ãããããã®è§£èª¬ãèããŠã¿ãŸãããã
ïŒæ®µéã®ãªãã¡ã¯ã¿ãªã³ã°ããé åºç«ãŠãŠè§£èª¬ããŠãããã®ã§åãããããã§ããRails ã§ã¯ãããã©ã«ãå€ããç解ããã®ããšãŠã倧åã§ããã³ãŒããã·ã³ãã«ã«ãªãã°ãªãã»ã©ããã®è£ã§ã¯ã©ãããåããããã®ããç解ããå¿ èŠãããã®ã§ããã²ãã®è§£èª¬ãèããŠç解ãæ·±ããŠããããã°ãšæããŸãã
Ruby ã®ã!ããš Rails ã®ã!ãã¯å¥ç©
Railsãã¥ãŒããªã¢ã«ã§åºŠã åºãŠããã!ãã¡ãœããã
ãïŒïŒç« åŸç·š ïŒ. Faker Gem ã䜿ããã§ãdb/seeds.rb
ã«ãµã³ãã«ãŠãŒã¶ãŒãäœãã³ãŒãã§åºãŠããæã¯ãäŸå€ãåºããããã«äœ¿ãããŠããŸãããã
Ruby ã®ã!ãã¯ãRailsã«ãããã!ããšã¯å
šãé¢ä¿ã®ç¡ããã®ã§ ãç Žå£çã¡ãœããããšåŒã°ããŠãããã§ããããã®éããåããããã説æããŠãããŠããéšåã ãïŒïŒç« åŸç·š ãã®è³ªåã³ãŒããŒã§ãã
åãã!ãã§ããRails ãš Rubyãããããéãæå³ããã£ãŠãããããã§ãããç¥ããªããšæ··ä¹±ããŠããŸãããã§ãã
ã¡ãŒã«èªèšŒã®ä»çµã¿
ãèªèšŒã㯠Railsãã¥ãŒããªã¢ã«å ã§ãããŸã§äœåºŠãè¡ãªã£ãŠããŸãããä»åã¯ã¡ãŒã«æ©èœã䜿ã£ãŠã®èªèšŒã§ãã
倧äœã®æµãã¯ä»ãŸã§ãšåããªã®ã§ãã ãïŒïŒç« åç·š ïŒ. ã¡ãŒã«èªèšŒã®ä»çµã¿ãã ã§ã¹ã©ã€ããèŠãªããã®èª¬æãèããŠã確èªããªããé²ãããšè¯ãããã§ãã
ïŒïŒç« ããã¯ãããŸã§ã®åºç€çãªå 容ã掻ãããå¿çšçãªãã®ã«ãªã£ãŠããŠãïŒïŒç« ãŸã§ãç解ããŠããã®ãåæã«ãªã£ãŠããŸããé£ãããšæããæã¯ãèªåãçŽåŸãããŸã§åŸ©ç¿ããã®ãäžã€ã®æ¹æ³ããªãšæããŸãã説æãèããŠãããããããªãå Žåã¯ãååã®èªèšŒã®ç解ãã§ããŠããªãå¯èœæ§ãããã®ã§ãïŒç« åŸç·š ïŒïŒ. ãã¹ã¯ãŒãã®å®è£ ãããïŒç« ïŒ. ãã°ã€ã³ç¶æ ã®èªèšŒããé çªã«æ¯ãè¿ã£ãŠèŠããšè¯ãããã§ãã
Action Mailer ã®æ£äœã«ã€ããŠã®è§£èª¬ ãïŒïŒç« åç·š ïŒïŒ. Action Mailer ã®å®æ ãšå®è£ ããèå³æ·±ãã®ã§ããããã§ãã
create ãš save ã®éã
ãã³ãŒã«ããã¯åŠçãã®æã®ãbefore_save ãš before_create ã®éãã§ãããã®ãµãã€ã®éã説æã§ããŸããïŒ
ãïŒïŒç« åç·š ïŒ. ã¡ãœããåç §çšã®ã¡ãœããã䜿ããã®ãšãããèŠãŠã¿ããšãäºã€ã®éãã«ã€ããŠæ確ã«èª¬æãããŠããŸãã现ããæãªã®ã§ãããããããæäžã€äžã€ããã¡ããšç解ã§ãããšæ°æã¡ããé²ããããšãã§ãããšæããŸãã
attr_accessor
ãããããªããšããæ¹ã¯ããäžåºŠ Cookies ã䜿ã£ãèªèšŒã®ä»çµã¿ã埩ç¿ããŸãããã
ã¡ã¿ããã°ã©ãã³ã°ã«è§Šãã
ïŒïŒç« ã§ã¯ãã¡ã¿ããã°ã©ãã³ã°ãšãããã®ã«è§ŠããããŠããŸãã
ããã¹ãã ãã§èŠããšãªãã ãé£ãããã«æããŸããâŠð
ãïŒïŒç« åŸç·š ïŒ. èªèšŒæ
å ±ãååŸãšæ¯èŒ ãã ã§ã¯ããªããã¡ã¿ããã°ã©ãã³ã°ãããã®ãïŒããšãããšãããã説æããããçŽåŸã§ãã解説ããããŸãã
ðŒã³ããå®è£ ãããã¯DRYãšã¯èšããŸãããâŠãã©ãããã°æœè±¡åã§ããã®ãïŒ
ããã§ãRuby ã®ãsendãã¡ãœããã®çŽ¹ä»ã§ããæååã䜿ããããã«ãªããšãããŸããªãã¡ã¯ã¿ãªã³ã°ããªããDRYã«åºæ¥ããã§ããRailsãã¥ãŒããªã¢ã«å ã§ã¯ããŸãå®è£ ã§ããããã«èšèšãããŠãããã©ãå®éã«äžããéçºããŠãã®æã䜿ããã®ã¯åãäºã ãããšãã解説ãé¢çœãã§ããèšèšã¯å€§äºã§ãïŒ
ãã¹ãã§äŸ¿å©ãªãassignsã
ïŒïŒç« ããŠãŒã¶ãŒç»é²ã®ãã¹ãã«ãã¡ãŒã«èªèšŒã®ã¢ã«ãŠã³ãæå¹åãè¿œå ãããšããã§åºãŠãã assigns
ã¡ãœãããïŒç« ã®æŒç¿åé¡ã§ãåºãŠããŠããŸããã
ã§ããããã¯ãããã¹ãã ãã§ã¯ç解ãã¥ããæ¹ããããšæãã®ã§ã解説åç»ã® ãïŒïŒç« åŸç·š ïŒ. assigns ã¡ãœãã ããèŠãŠã¿ãŸããããã¹ã©ã€ãä»ãã§èª¬æãããŠããŸãã
ãŸãã ãïŒïŒç« åŸç·š ïŒ. ãŸãšããšè³ªåã³ãŒã㌠ãã§ã質åè ãããã assigns ã¡ãœããã«ã€ããŠã®è³ªåããããã©ãããå Žåã«äœ¿çšããã®ãïŒãšãã£ã解説ãèããŸããã©ã¡ããçãæéã§èããã®ã§ãç¥ã£ãŠãããšäŸ¿å©ãª assignsãæ°ã«ãªãæ¹ã¯ãã²èŠããŠã¿ãŠãã ããã
beforeãã£ã«ã¿ãŒã§ãªãã¡ã¯ã¿ãªã³ã°
ïŒïŒç« ã®ãã¹ã¯ãŒãã®åèšå®ãå®è£ ãã倧äºãªã³ãŒãã®éšåãªã®ã§ãããã³ããã ãã§é²ããŠããã絶察ã«ç解ã§ããªããšãããªã®ã§ããã£ãããšåŠç¿ããã¹ããšããã§ãããïŒïŒç« åŸç·š ïŒ. ãã¹ã¯ãŒãã®æŽæ°ã ïŒ. before_filter ã®ããäžã€ã®äœ¿ãæ¹ãã§ã¯ãããã¹ãçã§ã¯è§ŠããããŠããªã解説ãçãã ãããã§ãã
ðŒãã£ã«ã¿ãŒããããªã䜿ãæ¹ã«èŠããŸãããRailsã®äžã§ã¯çµæ§äœ¿ãããææ³ã ããã§ãã
ðŒedit ã¢ã¯ã·ã§ã³ã¯ç©ºãªã®ã« editãã©ãŒã ãèŠããš@user
ã宣èšãããŠããïŒããã¯åããã¥ããããâŠã®å Žé¢ãDRYã«æžãã®ã¯ãã¡ãã倧äºã ãã©ãåããã¥ãããªããªãæ¬æ«è»¢åãããããªãâŠãšãè²ã
ãšèããããããéšåã§ãããèå³æ·±ãå
容ãªã®ã§ããªã¹ã¹ã¡ã®ç®æã§ãã
Ruby ãäžçå·ã䜿ã£ãæéãã®èªã¿æ¹
ïŒïŒç« User ã¢ãã«ã«ãã¹ã¯ãŒãåèšå®çšã¡ãœãããè¿œå ããå Žé¢ã§ããããããäºã¯ããã¹ã¯ãŒãåèšå®ã®æéãèšå®ããŠã2æé以äžãã¹ã¯ãŒããåèšå®ãããªãã£ãå Žåã¯æéåãã«ããäºã§ããã
ããã¹ãã§ã説æãããã®ã§ãããæéã®äžçå·ã¯ããªããªãç解ãé£ããã§ãããé£ãããšæããããæ¹ã¯ ãïŒïŒç« åŸç·š 6. ãã¹ã¯ãŒãæŽæ°ïŒã€ã®åŠç ãã®ã¹ã©ã€ããã¿ãªãã説æãèããŠã¿ããšè¯ãããã§ãã
ïŒããŸãïŒ
# æå»ã®æŒç®
# 2.hours.since(reset_sent_at).past?
# ã®æ¹ãèªã¿ãããã
2.hours.since(3.hours.ago).past?
# => true
2.hours.since(1.hours.ago).past?
# => false
ðŒç€Ÿå ã§çŽ¹ä»ããŠããã£ãã³ãŒããæ²èŒããŠãããŸãâšãããªé¢šã«ãæžãããã§ããã(@hanachin_ ããããããšãããããŸããã)
DBèšèšïŒã¢ããªã³ã°ïŒãäœéšãã
ïŒïŒç« ã® Micropost ã¢ãã«ãäœããšããã§ãã
ðŒè¡šãèŠãŠããã®éãã«ãã€ã°ã¬ãŒã·ã§ã³ãã¡ã€ã«ãäœæããŠããã°ããã®ã¯åããâŠãã§ããã©ããã£ãŠã«ã©ã ã®çš®é¡ãäœãã®ã決ããŠãããã ããïŒð€ããã¹ãçã§ã¯ãåãã®èª¬æã«çãŸã£ãŠããŸããã解説åç» ãïŒïŒç« åç·š ïŒ. Micropostã®å®è£ ã®é²ãæ¹ ãã§ã¯ã¢ãã¯ç»é¢ãèŠãªãããã©ããªé¢šã«è¿œå ããã«ã©ã ã決ããŠããã®ãèŠããããã«ãªã£ãŠããŸãã
ã©ã®æ
å ±ãDBã«ä¿åãã¹ãã§ãã©ã®æ
å ±ã¯ãããªãã®ããäžç·ã«èããŠããããšãã§ããŸãã
ãã€ãã¯èªåã§äœãäœãããïŒãšæãããŠããæ¹ãã»ãšãã©ã ãšæãã®ã§ã¢ããªã³ã°ãã§ãããšå¯èœæ§ãã°ã³ãšåºããããã§ããã
Rubyã->ããã®ç¢å°ã¯äœã ïŒ
ïŒïŒç« ã®ãã€ã¯ããã¹ããç¹å®ã®é åºã§ååŸãããïŒã®å Žé¢ã§ããdefault_scope
ãšãããã®ã䜿ã£ãŠ DB ããã«ã¯ã¬ãããèããŠããããšããã¯ããã¹ãçã®èª¬æã§ãåããããããšæããŸãããã->ããšããèšå·ã«ã€ããŠäœã ãé£ãã説æããããŸããð€
ãã©ã ãåŒãã ãProcãªããžã§ã¯ãããªã©åããŠèãæ¹ãå€ããšæããŸãã
ðŒãä»ããããããªããŠãå¿é ãããªãããã©ããã£ã±ãæ°ã«ãªã£ãŠããŸãâŠããããªæ¹ã¯ ãïŒïŒç« åç·š ïŒ. Micropostã¢ãã«ã®é åºãšäŸå ããèŠãŠã¿ãŸãããã
ðŒRailsã§ãã䜿ãããŠãããyieldããå®ã¯ãã®ä»çµã¿ã䜿ãããŠãããªã©ãèå³æ·±ã解説ããããŸããç¥ãã°ç¥ãã»ã©ãRailsãRubyã®æ·±ãéšåãã©ãã©ãæ°ã«ãªããŸããã
芪ã¯ã©ã¹ãžç§»åããããªãã¡ã¯ã¿ãªã³ã°
ãã€ã¯ããã¹ãã® create ã¢ã¯ã·ã§ã³ã destroy ã¢ã¯ã·ã§ã³ã«ã¢ã¯ã»ã¹åºæ¥ãã®ã¯ããã°ã€ã³æžã¿ã®ãŠãŒã¶ãŒã§ãªããã°ãããŸãããUsers ã³ã³ãããŒã©ã§ã䜿ã£ã logged_in_user
ã¡ãœããã䜿ãããã§ããããããããã§åãã¡ãœããã Microposts ã³ã³ãããŒã©ã«ã³ããå®è£
ããã¹ããïŒã解説ããŠãããã®ã ãïŒïŒç« äžç·š ïŒ. filter ã䜿ã£ãŠã¢ã¯ã»ã¹å¶é ãã§ãã
ãã®è§£èª¬åç»ã§äœåºŠãèšãããŠããéããåãã³ãŒããæžããšããã®ã¯ Rails ã®èšèšææ³ã®ãDRYãã«åããŠããŸããŸããâŠã
è€æ°ã®ã³ã³ãããŒã©ããŸããã§ãåãã¢ã¯ã·ã§ã³ãããå Žåã¯ãããªé¢šã«æžãã°ãDRYã«å®è£ ããŠããããšããäºãåãããŸããããã¯ãã¥ãŒã§ãã¢ãã«ã§ãåãäºãèšããã®ã§ãã¯ã©ã¹ç¶æ¿ãäžæã䜿ã£ããªãã¡ã¯ã¿ãªã³ã°è¡ãèŠããŠãããŸãããã
ããŒã·ã£ã«ã®ãšã©ãŒã¡ãã»ãŒãžã䜿ãåã
ïŒïŒç« ããã€ã¯ããã¹ãæçš¿ãã©ãŒã ã«ããšã©ãŒã¡ãã»ãŒãžã®ããŒã·ã£ã«ãä»ããŠãããšããã§ãã
ããã® render ã«åŒæ° object: f.object
ãæž¡ãããŠãããšããã§ãããç解ãé£ãããããããŸããããïŒïŒç« åŸç·š ïŒ. Micropost ã®æçš¿ãã©ãŒã ãã§ãã®éšåã詳ãã解説ããŠããŸãã
ðŒ_error_messageså ã®ã³ãŒãã @user ã§ã @micropost ã§ã䜿ããããã«ãããã
shared/error_messages
ã«ãªãã·ã§ã³ã§åŒæ°ãæž¡ããšãªã«ãèµ·ããã®ãïŒãç解ã§ãããšäžæ°ã«åããããã«ãªããšæãã®ã§ãããã¹ãã ãã§ã¯é£ããæ¹ã«ããããã®è§£èª¬ç®æã§ãã
Railsã¬ã€ããèŠããšä»ã«ãããããªäºãåºæ¥ãããšãåãããŸããæŽã«è©³ããç¥ãããæ¹ã¯ã芧ãã ããã
äžã€åã®URLãè¿ã request.referrer
ãã€ã¯ããã¹ããåé€ããå Žé¢ã§ãã
ðŒcorrect_user ãã£ã«ã¿ãŒã䜿ã£ãŠãä»ã®äººã®æçš¿ã¯åé€ã§ããªãããã«ããŸããããã® destroy ã¢ã¯ã·ã§ã³ã«åºãŠãã request.referrer || root_url
ãšããã³ãŒããå°ãé£ãããããããŸããã
ãïŒïŒç« åŸç·š ïŒ. ãã€ã¯ããã¹ããåé€ãã®åŸåéšåãèŠãŠã¿ããšããã®ã³ãŒãã«ã€ããŠè©³ãã説æããããŸãã
ðŒäžã€åã®ããŒãžã«ã¯ãäœãã¿ãŒã³ãããïŒã®å Žé¢ããããèŠãããšäŸ¿å©ããã§ããã request.referrer
ã«ãŸã€ããã¡ãã£ãšé¢çœãèšäºãçºèŠããã®ã§èŒããŠãããŸãã
accept ã§ããã³ãåŽã«ãããªããŒã·ã§ã³
ãïŒïŒç« åŸç·š ïŒïŒ. ç»åã®å å·¥ãæ€èšŒ ãã§ã¯ãç»åãæçš¿ããéã«ããã³ãåŽã§ãããªããŒã·ã§ã³ããããŠãããæ¹æ³ã«ã€ããŠåŠã¹ãŸããããã®å Žé¢ã¯å®éã«åç»å ã®ãã¡ã€ã«ã¢ããããŒããŒãèŠãªããé²ããããŠããã®ã§ãããã¹ãã ãã®æãããäœæçã«åŠã¹ãŸãã
ðŒããã¯ãšã³ãã§æçš¿ã§ããç»åã®çš®é¡ãæå®ããŠããªããŒã·ã§ã³ããããŠãããŠãããŸã éžæã§ããŠããŸããã¢ããããŒãèªäœã¯ã§ããŠããŸããïŒã¢ããããŒãåŸãããªããŒã·ã§ã³ã®ãšã©ãŒã¡ãã»ãŒãžãåºããïŒåãããéžã¹ãªãããã«ããã«ã¯ã©ãããã°ããã®ã ããïŒ
ãã®éšå㯠Rails ã®æ©èœã§ã¯ãªãHTML ã®æ©èœã®è§£èª¬ã§ããRailsãã¥ãŒããªã¢ã«ã§ã¯ããã®ä»ã«ã jQuery ã䜿ã£ããã¡ã€ã«ãµã€ãºã®å¶éãããã³ãåŽã§ãç¥ããããæ©èœãåŠç¿ã§ããããã«ãªã£ãŠããŸããå¹ åºãç¥èãåŠã¹ãããã«ãªã£ãŠãããã§ããã
ãã©ããŒ&ãã©ãã¯ãŒã®ã¢ãã«èšèš
ïŒïŒç« ã®ãã©ããŒãšãã©ãã¯ãŒãã©ãèšèšãããïŒãç解ããã®ã¯é£ãããšããã ãšæããŸããMicropost ã¢ãã«ãç䌌ãŠèšèšããããšãããšããªããªãé£ãããã§ãããä»ãŸã§ã®ãŠãŒã¶ãŒããã€ã¯ããã¹ãã¢ãã«ãšã©ããéã£ãŠé£ããæããã®ã§ããããïŒãŸãã¯ãã©ããŒãããšã¯ã©ãããäºããããäžå¯§ã«è§£èª¬ããŠãããã®ã ãïŒïŒç« åç·š ãã§ãã
ãã®å®è£
æ¹æ³ã¯ ãïŒïŒç« åç·š ïŒ. Relationshipã¢ãã«ã®å®è£
ãããããã£ããèããŠã¿ããšãããã¹ãã ãã ãšåããã¥ããéšåãç解ãããããªã£ãŠããŸããäžã§ã ãïŒ. active_relationships ã®ç¢ºèªãã® 38:55ã ããã®èª¬æ㯠belongs_to
ã has_many
ã®å®æ
ã«ã€ããŠèª¬æãããŠããŠããããŸã§ã¢ã€ã¢ã€ããŠããããšãäžæ°ã«è§£æ¶ãããæ¹ãå€ãã®ã§ã¯ãªãããšæããŸãã
has_many
ãattr_accessor
ãªã©ããšãã£ã¿å
ã§è²ãä»ããŠããã®ã«ã¯ããã圹å²ãããããã ã£ãã®ã§ããããã¯ãã²èããŠã»ããããããã®ç®æã§ãã
ãïŒïŒç« åç·š ïŒïŒ. 質åã³ãŒã㌠ãã® 1:00:42ã ã§ã¯ãã¢ãã«èšèšã®å€§äºããç¥ãããšãã§ããŸãã
ãïŒïŒç« åç·š ïŒïŒ. ã¡ãœãããå®çŸ©ããå Žæ ãã§ã¯ãfat ã³ã³ãããŒã©åé¡ããšãããã®ã«ã€ããŠè§£èª¬ããããŸãããããDRYã«æžãããã®å€§äºãªææ³ãªã®ã§å匷ã«ãªããŸãã
resourcesã®æ°ããªäœ¿ãæ¹
ãïŒïŒç« åŸç·š ïŒ. following ãš follower ã® routing ãè¿œå ãã ãã®éšåã§ããä»ãŸã§ãresources :users
ãšããã«ãŒãã£ã³ã°ã䜿ã£ãŠããŸããããã®ïŒè¡ã§è²ããªã«ãŒãã£ã³ã°ãäœããããšãŠã䟿å©ã§ãããã
ä»åã¯ãæŽã«å¥œããªã«ãŒãã£ã³ã°ãè¿œå ããæ¹æ³ãåŠã³ãŸããRailsã¬ã€ãã® member ã«ãŒãã£ã³ã°ã®è§£èª¬ãåãããããã§ããã
ç°ãªãã¢ã¯ã·ã§ã³ãïŒã€ã®ãã¥ãŒã§å®è£
ãïŒïŒç« åŸç·š ïŒ. Following ãš Followers ã®å®è£ ãã®ãšããã§ãã
ã¢ã¯ã·ã§ã³ã¯éããã©ãäžã€ã®ãã¥ãŒãããŸã䜿ãåããŠå ±éã§äœ¿ãããã®ã«ããŠããããšããå®è£ æ¹æ³ã§ãã
ãã¥ãŒããªã¢ã«å ã§ã¯ãã®ãããªå®è£ æ¹æ³ãã§ããããšãã玹ä»ã«ããããå®è£ æ¹æ³ã¯ã¢ã€ãã¢æ¬¡ç¬¬ã§è²ããªããšãã§ããã®ã§ããã®å®è£ æ¹æ³ã®æ¹ãã¯ãŒã«ã ããšããã®ãèŠã€ããŠã¿ãã®ãé¢çœããã§ããã
Ajax 㧠Follow ãã¿ã³ãå®è£ ãã
Rails ãã¥ãŒããªã¢ã«ã§ã¯ãFollowã»Unfollow ãã¿ã³ã®å®è£ æ¹æ³ãïŒéã玹ä»ããŠãããŠããŸããå¿çšç·šãšããŠãAjax ã䜿ã£ãå®è£ æ¹æ³ã玹ä»ããŠãããŠããã®ã ãïŒïŒç« åŸç·š ïŒïŒ. Followãã¿ã³ ajax å®è£ ç·š ãã§ãã
å€æŽããããéšåã ãã JavaScript ã®åã䜿ã£ãŠãã£ãšå€ããŠããããšããæã Ajax ã§ãã
ðŒ Follow ãã¿ã³ãæŒããŠãå€ããéšåã¯ã©ãã ããïŒ
ããã§ã¯ ãJavaScript ã¯äœ¿ãå Žæãåå³ããå€çšããã¹ãããããšãã£ããããã¹ãçã§ã¯è§ŠããããŠããªã話ãèããŸããäžèŠã䟿å©ããã§è²ããªãšããã§äœ¿ããããªã Ajax ã ãã©æ éã«äœ¿ãã¹ãã ãšããèå³æ·±ãå 容ã«ãªã£ãŠããŸããAjax ã®å®è£ æ¹æ³ãåããããã解説ãããŠãã®ã§ã詳ããç¥ãããæ¹ã¯ãã²èããŠã¿ãŠãã ããã
ãã®äžã§åºãŠãã respond_to
ã¡ãœããã«ã€ããŠã¯ ãïŒïŒç« åŸç·š ïŒïŒ. 質åã³ãŒã㌠ã2:04:30ã ä»è¿ã§ãããªã詳ãã解説ãããã®ã§ãåãããŠèŠãŠã¿ããšæŽã«ç解ãæ·±ãŸããšæããŸãã
.jsonã.mdã䜿ã£ãå®éã®ãã©ãŠã¶ç»é¢ãèŠããŠãããããšããã¥ãŒããªã¢ã«ã®å 容ã«ãšã©ãŸããæ§ã ãªããšãåŠã¹ãã®ã解説åç»ã®ãããšããã§ããã
SQL ã«è§Šãã
ãïŒïŒç« åŸç·š ïŒïŒ. ã¹ããŒã¿ã¹ãã£ãŒããå®æããã ããããæåŸã®é£é¢ãã¹ããŒã¿ã¹ãã£ãŒããã®å®è£ ã§ãã
Twitterã§ããã¿ã€ã ã©ã€ã³ã®ãããªãã®ã§ããããã®éšåã§ã¯ã SQL ãã«è§ŠããããŠããŠãçµæ§é£ããæããæ¹ãå€ããšæããŸãã
解説åç»ã§ã¯ SQL æã«åããŠè§Šãããšããæ¹ã§ãåãããããããã«èª¬æããããŸãããRails ãã¥ãŒããªã¢ã«ã®åæç¥èã®éšåã§ãããããã«ã Progate ã®ãSQL ã³ãŒã¹ããªã©ã§åºç€çãªãšãããåŠç¿ããŠãããšããã£ãšæ¥œã«é ã«å ¥ã£ãŠãããšæããŸãã
ãïŒïŒç« åŸç·š ïŒïŒ. ãµãã»ã¬ã¯ãã䜿ã ãããã¯ãè€éãªæ€çŽ¢çµæãé«éã«åŒã£åŒµã£ãŠãããSQLã®æã«ã€ããŠåŠã¹ãŸãã
ãã® SQL æã èªã¿ãããåŒå±éããŠæžããŠã¿ãããã®å Žé¢ã§ãã
ããã¹ãã ãã ãšé£ããæããããéšåã§ãããããŸã解説åç»ãå©çšããªããç解ããŠããã ããã°ãšæããŸãã
ããšãã
ãã®è§£èª¬åç»ã§ã¯ãããã¹ãçã ãã§ã¯ç解ãã¥ããéšåãäžå¯§ã«è§£èª¬ããŠããããã ãã§ã¯ãªãããã¥ãŒããªã¢ã«ã®å 容以å€ã®æ§ã ãªããšãåŠã¶äºãã§ããŸãã
çŸå Žã«ããè¿ãå ·äœçãªèª¬æãèãããšã§ããã£ãšç¥èãæ·±ãŸããšæããŸããããããããã°ã©ãã³ã°ãåŠãã§ããæ¹ã«ã¯ãã¡ãããæŽã«ç¥èã®å®çãã¯ãã£ãŠã¿ããæ¹ã«ããå§ãã§ããåç»ã§ãããã£ãšèŠãŠäžãã£ãçããã«ãããããè²ããªæ°ä»ãããããšæããŸãð
ä»åç§ã¯ãæ³äººãã©ã³ãã§åç»ãèŠãããŠããã ããã®ã§ããã瀟å¡ç ä¿®ãªã©ã§å€§ãã«åœ¹ç«ã£ãŠããããã ãšæãã®ã§ãã玹ä»ãããŠããã ããŸãã
ðŒãããªé¢šã«ããã·ã¥ããŒãã§ç°¡åã«ç®¡çãã§ããå šå¡åã®åç»ãè²·ããããã³ã¹ããããããªãã®ã§ãç ä¿®ã«ããã¿ãªã§ããâš
ðŒïŒãã³ããã§èŠãŠãã®ãç§ã§ãâŠ!!ïŒ
ããã§ã¯æåŸãŸã§æ¬èšäºãèŠãŠé ããããããšãããããŸãããRailsãã¥ãŒããªã¢ã«è§£èª¬åç»ããçããã®åŠç¿ã®ã圹ã«ç«ãŠãã°å¬ããæããŸãã
æè¿ã®ãç¥ãã
- 12/02 ð€ ãããŽãã¯ãªã¹ãã¹äŒ@æ±äº¬ã«åè³
- 11/18 ð Ryukyufrogs ã«åŠç¿æ¯æŽã§åè³
- 11/13 ð Railsã¬ã€ãã Rails 8.0 ã«å¯Ÿå¿ããŸãã
- 11/12 ð€ ã€ã³ã¿ãã¥ãŒåé²ãçåŠããèµ·æ¥ãŸã§ã
- 11/08 ð RubyWorld Conference 2024 ã«ç»å£
- 08/28 ð JPHACKS 2024 ã«åŠç¿æ¯æŽã§åè³
- 08/16 ðRailsã¬ã€ãã Rails 7.2 ã«å¯Ÿå¿ããŸãã
- 08/14 ð åè³ãã©ã³å°å ¥äºäŸ: èã®ç©Žã©ã
- 07/19 ð AWSè³ã®å¯è³ãåãåããŸããïŒ
- 07/10 ð åè³ãã©ã³å°å ¥äºäŸ: GA technologies