Railsã®URLè¨è¨ãèãã¦ã¿ã(6) è¨è¨ã®é¸æè¢
ä»åã¯ç´æ¥Railsã¨ã¯é¢ä¿ãªãã®ã§ãããå æ¥ãããããã¼ã¸ãè¦ã¤ãã¾ããã
ããã¯2009å¹´ã«æ¸ããããã®ã®ããã§ãããURLè¨è¨ã«é¢ããéè¦ãªèãæ¹ãããããæ¸ããã¦ãã¾ãã
ãã®ä¸ã«ããã®ããã°ã®ã·ãªã¼ãºã®(4) スラッシュと「持っている」関係ã(5) Railsのリソースパターンã®å段éã«ãªããããªâChoosing a URI schemes for resource hierarchiesâã¨ãã話ããã£ãã®ã§ãããã¤ã¾ãã§ç´¹ä»ãããã¨æãã¾ãã
ãªã½ã¼ã¹ã®é層ã«å¯¾ãã¦ãã©ãããURLãè¨è¨ãããï¼
åæã¨ãã¦ãè¨è¨ããWebãµã¤ãã«ã¯ãconversationï¼ä¼è©±ï¼ã¨ãããªã½ã¼ã¹ãè¤æ°ãããããããã®ãªã½ã¼ã¹ã¯ã¦ãã¼ã¯ãªIDã§åºå¥ãããã¨ãã¾ããï¼IDã¯æ°åã¨ã¯éããªãèå¥åï¼
/conversations
㨠/conversation/{id}
/conversations
ã§ãã¹ã¦ã®ä¼è©±/conversation/{id}
ã§ID=id
ã®ä¼è©±
å
¨ä½ã®ä¼è©±ã¯è¤æ°å½¢ãç¹å®ã®1ã¤ã®ä¼è©±ã¯åæ°å½¢ã¨ããèãæ¹ã
è±èªã¨ãã¦ã¯èªç¶ãªã®ããããã¾ãããããããã使ãåããã»ã©ã®æ義ã¯èãããå¾è
ã§ãã¹ãåã£ã /conversation
ã¯ä½ãæãã®ãã¨ããåé¡ãæ®ãã¾ãã
/conversations/conversation/{id}
/conversations
ã§ãã¹ã¦ã®ä¼è©±/conversations/conversation/{id}
ã§ID=id
ã®ä¼è©±
å
ã»ã©ã¨æ¯ã¹ãã¨1種é¡ã®ãã¹ã«çµ±åããã¾ãããããã¯ã /conversations/conversation
ãä½ãæãã®ããè¬ã§ãã
/conversations/{id}
/conversations
ã§ãã¹ã¦ã®ä¼è©±/conversations/{id}
ã§ID=id
ã®ä¼è©±
Railsæ¹å¼ã§ããããã§ãã¹ãåã£ã¦ãåé¡ãªããªãã¾ããããã ããæ°ããä¼è©±ãä½æããããã®ç»é¢ã«ç¨ãã /conversations/new
ã¨ããè£å©çãªã½ã¼ã¹ããID=new
ã®ãªã½ã¼ã¹ã¨åºå¥ã§ããªããªãã¨ããåé¡ãããã¾ããããã¯æ¯è¼çå°ããªåé¡ã§ã¯ããã¾ãããåã®2ã¤ã®æ¹å¼ã§ã¯ãã®åé¡ã¯èµ·ããã¾ããã
/conversations/conversation-{id}
/conversations
ã§ãã¹ã¦ã®ä¼è©±/conversations/conversation-{id}
ã§ID=id
ã®ä¼è©±
ããã解決ããæ¹æ³ããã ãã¡ãã£ã¨åé·ã§ã¯ããã¾ãã
æ·±ãé層
次ã«ãããããã®conversationãtodo listï¼ãããã¨ãªã¹ãï¼ã¨ãããªã½ã¼ã¹ãè¤æ°æã£ã¦ããã¨ãã¾ãã
/conversations/{cid}/todo-lists/{tid}
/conversations/{cid}/todo-lists
ã§ID=cid
ã®ä¼è©±ãæã¤ãã¹ã¦ã®ãããã¨ãªã¹ã/conversations/{cid}/todo-lists/{tid}
ã§ID=cid
ã®ä¼è©±ãæã¤ID=tid
ã®ãããã¨ãªã¹ã
Railsæ¹å¼ãåç¯ã¨åãåé¡ã¯å¼ãç¶ãã¾ãã
ã¾ãã /conversations/{cid}/todo-lists
ï¼ãããã¨ãªã¹ãã®å
¨ä½ï¼ã¯å®éã«ã¯å¿
è¦ãªãã /conversations/{cid}
ãããã°ããã§ååãªãã¨ãããã¾ã((æ¥ä»ãURLã«å
¥ããã¨ãããããã /years/2012/months/01/days/03
ã¨ããå¿
è¦ããªãã®ã«ãä¼¼ã¦ãã¾ã))ã
/conversations/{cid}/{tid}
/conversations/{cid}/{tid}
ã§ID=cid
ã®ä¼è©±ãæã¤ID=tid
ã®ãããã¨ãªã¹ã
tid
ãä½ãæãã¦ããã®ãããããããã¾ãããæ¥ä»ãªã©æããã«ããããããªå ´åãªãçãã¦ããæ¹å¼ã§ãããã
/conversations/conversation-{cid}/todo-list-{tid}
/conversations/conversation-{cid}/todo-lists-{tid}
ã§ID=cid
ã®ä¼è©±ãæã¤ID=tid
ã®ãããã¨ãªã¹ã
åç¯ã®æå¾ã®æ¹æ³ãæ¡ç¨ãã¤ã¤ãtodo listã®å ¨ä½ã¯ãããªãã®ã ããããã®ãã¹é層ã ããªãããæ¹å¼ããã®æ¹å¼ã ã¨ãå ¨ä½ã®ãªã½ã¼ã¹ã¨åå¥ã®ãªã½ã¼ã¹ã®ã©ããæä¾ãã¦ããããæ確ã«ãªãã¾ãã
ç§è¦
Railsæ¹å¼ã§ãããããï¼ç¬ï¼
ã¨è¨ã£ã¦ãã¾ãã¨å
ãåããªãã®ã§ããããããããããªè°è«ãçµã¦ãä»ã®Railsã®ãªã½ã¼ã¹ãã¿ã¼ã³ï¼Memberãªã½ã¼ã¹ãCollectionãªã½ã¼ã¹ãªã©ï¼ãå®ã¾ã£ã¦ããã®ã§ã¯ãªãããã¨æ³åã§ãã¾ãã
Railsæ¹å¼ã«ããã /conversations/new
ã®åé¡ç¹ã«ã¤ãã¦ã¯ãå®ã¯éå»ã«ã¯ /conversations;new
ã¨ãªã£ã¦ããææãããã¾ããããããªãåé¡ã¯èµ·ããªãã®ã§ãããã»ãã³ãã³ãä¸èªç¶ã§ãã¾ãåãå
¥ããããªãã£ãã®ããããã«ã¹ã©ãã·ã¥ã«å¤ããã¾ããã
å人çãªèãã§ã¯ãããããè£å©çãªãªã½ã¼ã¹ã¯â_
âã§å§ãããã¨ã¨ãã¦ã /conversations/_new
ã¨ããã°ããã®ã§ã¯ã¨æã£ã¦ãã¾ã*1ããã ãRailsã®è¦ç´ã§â_
âã¯partial viewãæãã®ã§ãã¡ãã£ã¨ç¸æ§ãæªãããããã¾ããã
ãã¡ãããRailsã使ãã¨ãããããã®æ¹å¼ã®ã©ããå®éã«æ¡ç¨ãããã¯èªç±ã§ããroutes.rbã®æ¸ãæ¹æ¬¡ç¬¬ã§ãã©ã®ãããªæ¹å¼ã«ãããã¨ãã§ãã¾ãããã ãRailsã®ãã¿ã¼ã³ã«å¾ã£ã¦resources
ã§æ¸ãã®ã楽ã§ããã