ð 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