Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ruby on Rails講義 第18回, 第19回 Rails基礎

Ruby on Rails講義 第18回, 第19回 Rails基礎

おみくじアプリつくり

Kuniaki IGARASHI

October 17, 2012
Tweet

More Decks by Kuniaki IGARASHI

Other Decks in Technology

Transcript

  1. 3VCZPO3BJMTߨٛ ୈճ ୈճ3BJMTجૅ ,VOJBLJ*("3"4)*JHBJHB  BUҰڮେֶ ࣾձՊֶʹ͓͚Δ৘ใٕज़ͱίϯςϯπ࡞੒*7 χϑςΟגࣜձࣾدෟߨٛ

  2. χϑςΟגࣜձࣾ ఏڙ

  3. ߨࢣ ޒेཛྷ๜໌ גࣜձࣾສ༿ɹΤϯδχΞ

  4. ࿈བྷ ݄೔ͷߨٛ͸ٳߨͰ͢ɻ

  5. ͓Έ͘͡ΞϓϦ IUUQXXXqJDLSDPNQIPUPTQPVDIJO

  6. ͓Έ͘͡ΞϓϦ׬੒༧૝Πϝʔδ

  7. ͓Έ͘͡ΞϓϦͭ͘Γ खॱ 3VCZͰ͓Έ͘͡ΫϥεΛ࡞Δ 3BJMTͰΞϓϦΛ࡞Δ ΞϓϦʹ͓Έ͘͡ΫϥεΛ૊ΈࠐΉ

  8. ͓Έ͘͡ΞϓϦͭ͘Γ खॱ 3VCZͰ͓Έ͘͡ΫϥεΛ࡞Δ 3BJMTͰΞϓϦΛ࡞Δ ΞϓϦʹ͓Έ͘͡ΫϥεΛ૊ΈࠐΉ

  9. 3VCZͰ͓Έ͘͡ΫϥεΛ࡞Δ ཁ݅  ˞ཁ݅ຬͨ͢΂͖৚݅

  10. 3VCZͰ࡞Δ͓Έ͘͡Ϋϥεཁ݅ ͓Έ͘͡ɺϥοΩʔΧϥʔɺ ϥοΩʔͳํ֯ΛऔಘՄೳɻ಺༰͸ҎԼɻ ͓Έ͘͡ େ٢٢த٢খ٢ڟ ϥοΩʔΧϥʔ ੺੨ԫ྘ ϥοΩʔͳํ֯ ౦੢ೆ๺

  11. 3VCZͰ࡞Δ͓Έ͘͡Ϋϥεཁ݅ ͓Έ͘͡͸ϥϯμϜͰ݁Ռ͕มΘΔΑ͏ ʹ͍ͯͩ͘͠͞ɻ ຖճಉ݁͡ՌʹͳΒͳ͍Α͏ʹͯͩ͘͠͞ ͍ɻ

  12. 3VCZͰ࡞Δ͓Έ͘͡Ϋϥεཁ݅ JSCͰ࣍ͷΑ͏ʹ࣮ߦ͢Δͱɺ಺༰ͷೖ ͓ͬͨΈ͘͡ͷ݁Ռ͕ʮ͓Έ͘͡ΦϒδΣ Ϋτʯͱͯ͠औಘͰ͖ΔΑ͏ʹ͠·͢ɻ ͭ·ΓɺPNJLVKJSCΛ࡞ͬͯͦͷதʹ 0NJLVKJΫϥεΛ࣮૷͠·͢ɻ SFRVJSFPNJLVKJ PNJLVKJ0NJLVKJOFX

  13. 3VCZͰ࡞Δ͓Έ͘͡Ϋϥεཁ݅ ʮ͓Έ͘͡ΦϒδΣΫτʯ͔Β͸ ࣍ͷΑ͏ʹͯ͠಺༰ΛࢀরͰ͖ΔΑ͏ʹ͠·͢ɻ PNJLVKJ0NJLVKJOFX PNJLVKJOBNFେ٢ PNJLVKJMVDLZ@DPMPS੨ PNJLVKJMVDLZ@EJSFDUJPOೆ

  14. ԋशɿ3VCZͰ࡞Δ͓Έ͘͡Ϋϥε ώϯτ ཚ਺ΛಘΔʹ͸SBOEΛ࢖͍·͢ɻͨͱ͑͹ SBOE  ͸ʙͷͲΕ͔Λฦ͠·͢ɻ ΫϥεOFXͨ͠ͱ͖ʹ͸ɺJOJUJBMJ[Fϝιο υ͕ݺ͹Ε·͢ɻ 3VCZͷจ๏͸ߨٛࢿྉୈճɺ·ͨ͸ʮͨͷ ͍͠3VCZʯɺωοτΛࢀরͯ͠Έ͍ͯͩ͘͞ɻ

    IUUQTHJUIVCDPNIJUPUTVCBTIJSVCZMFDUVSF લड़ͷཁ݅Ͱ࣮૷͍ͯͩ͘͠͞ɻ
  15. 3VCZͰ࡞Δ͓Έ͘͡Ϋ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OE  > !MVDLZ@EJSFDUJPO<౦ ੢ ೆ ๺><SBOE  >                                 FOE FOE ԋशղઆɿ3VCZͰ࡞Δ͓Έ͘͡Ϋϥε !OBNF<େ٢ ٢ த٢ খ٢ ڟ><SBOE  > ͷSBOE  ͸dͷ஋ΛϥϯμϜʹฦ͠·͢ɻ<େ٢ ٢ த ٢ খ٢ ڟ>͸഑ྻͰ͢ɻ഑ྻ<Y>ͰY൪໨ͷཁૉΛऔΓग़ͤ· ͢ɻ͸͡·Γͳ͜ͱʹ஫ҙɻྫ͑͹<େ٢ ٢ த٢ খ ٢ ڟ><>͸த٢Ͱ͢ɻ
  20. DPEJOHVUG DMBTT0NJLVKJ BUUS@SFBEFSOBNF MVDLZ@DPMPS MVDLZ@EJSFDUJPO EFGJOJUJBMJ[F !OBNF<େ٢ ٢ த٢ খ٢

    ڟ><SBOE  > !MVDLZ@DPMPS<੺ ੨ ԫ ྘><SBOE  > !MVDLZ@EJSFDUJPO<౦ ੢ ೆ ๺><SBOE  >                                 FOE FOE ԋशղઆɿ3VCZͰ࡞Δ͓Έ͘͡Ϋϥε BUUS@SFBEFSOBNF͸!OBNFΛฦ͢ϝιουΛ࡞Γ·͢ɻҎԼ ͱಉ͡Ͱ͢ɻ EFGOBNF !OBNF FOE
  21. ͓Έ͘͡ΞϓϦͭ͘Γ खॱ 3VCZͰ͓Έ͘͡ΫϥεΛ࡞Δ 3BJMTͰΞϓϦΛ࡞Δ ΞϓϦʹ͓Έ͘͡ΫϥεΛ૊ΈࠐΉ 3VCZͰಈ͓͘Έ͘͡Ϋϥε͕Ͱ͖·ͨ͠ɻʋ ˜A ϊ

  22. ͓Έ͘͡ΞϓϦͭ͘Γ खॱ 3VCZͰ͓Έ͘͡ΫϥεΛ࡞Δ 3BJMTͰΞϓϦΛ࡞Δ ΞϓϦʹ͓Έ͘͡ΫϥεΛ૊ΈࠐΉ ͭ͗͸3BJMTͰΞϓϦΛ࡞ͬͯΈ·͠ΐ͏ɻ ͔͜͜Β͸ԋशʹ͠·͢ɻࣗ෼ͰࢿྉΛಡΈͳ͕Β ࡞ͬͯΈ͍ͯͩ͘͞ɻ

  23. DEGPSUVOFT CVOEMFFYFDSBJMTHDPOUSPMMFSUPEBZJOEFY ͓Έ͘͡ΞϓϦͭ͘Γ 3BJMT3PPU΁Ҡಈͯ͠ϖʔδͷͻͳ͕ͨΛͭ͘Δ IUUQMPDBMIPTUUPEBZJOEFY ϒϥ΢β͔ΒҎԼͷ63-ʹΞΫηε͢Δ ࠓ೔ͷӡ੎Λදࣔ͢ΔΞϓϦΛͭ͘Γ·͢ɻ CVOEMFFYFDSBJMTT SBJMTOFXGPSUVOFT 3BJMTΞϓϦΛͭ͘Δ

    8FCαʔόΛىಈ͢Δ T͸TFSWFSͷུͰ͢ɻ˞ऴྃ͸$USM D PS$USM 1BVTF  ͜Μͳը໘͕ग़·͢‎
  24. ͓Έ͘͡ΞϓϦͭ͘Γ खॱ 3VCZͰ͓Έ͘͡ΫϥεΛ࡞Δ 3BJMTͰΞϓϦΛ࡞Δ ΞϓϦʹ͓Έ͘͡ΫϥεΛ૊ΈࠐΉ ͦͯ͠ɺ͜͜·Ͱʹ࡞ͬͨͭΛ૊Έ߹Θͤ·͢ɻ

  25. ࠓ೔ͷӡ੎Λදࣔͤ͞Δ PNJLVKJSCΛMJCͷԼʹίϐʔ͠·͢ɻ MJCPNJLVKJSC ͱ͍͏ϑΝΠϧ͕͋ΔΑ͏ʹ഑ஔ͢Ε͹0,Ͱ͢ɻ

  26. IUUQMPDBMIPTUUPEBZJOEFY ࠓ೔ͷӡ੎Λදࣔͤ͞Δ ͜Μͳը໘͕ग़Ε͹0,Ͱ͢ɻ‎ I)FMMPJOEFYI Q'JOENFJOBQQWJFXTUPEBZJOEFYIUNMFSCQ BQQWJFXTUPEBZJOEFYIUNMFSC ͱͳ͍ͬͯΔͱ͜ΖΛҎԼͷΑ͏ʹमਖ਼͠·͢ɻ SFRVJSFMJCPNJLVKJSC !PNJLVKJ0NJLVKJOFX Iࠓ೔ͷӡ੎I

    I!PNJLVKJOBNFI QϥοΩʔΧϥʔɿ!PNJLVKJMVDLZ@DPMPSQ QϥοΩʔͳํ֯ɿ!PNJLVKJMVDLZ@EJSFDUJPOQ ͖͞΄Ͳಉ༷ʹϒϥ΢βͰҎԼ΁ΞΫηε ࣍ʹɺ
  27. ղઆɿ7JFXʹ3VCZͷίʔυΛຒΊࠐΉ 7JFXʹ3VCZͷίʔυΛຒΊࠐΉͭͷύʔπ͕͋Γ·͢ɻ ͱͰ͢ɻ !PNJLVKJ0NJLVKJOFX Ͱғ·Εͨ3VCZͷίʔυΛ࣮ߦͯ͠ɺ݁ՌΛग़ྗ͠· ͢ɻද͍ࣔͨ͠ͱ͖ʹ࢖͍·͢ɻ QϥοΩʔΧϥʔɿ!PNJLVKJMVDLZ@DPMPSQ  ྫ ྫ

    Ͱғ·Εͨ3VCZͷίʔυΛ࣮ߦ͠·͕͢ɺ݁ՌΛग़ྗ ͠·ͤΜɻॲཧ͚ͩΛߦ͏৔߹ʹ࢖͍·͢ɻ ʹ
  28. $POUSPMMFS΁ॲཧΛҠಈ͢Δ 7JFX͸දࣔΛ͢Δ໾ׂΛड͚࣋ͭ෦෼ͳͷͰɺදࣔ෦෼͚ͩΛ࢒ͯ͠ ॲཧ͸ίϯτϩʔϥ΁Ҡಈ͠·͢ɻ ҎԼͷϑΝΠϧΛมߋͯ͠ɺϒϥ΢β͔ΒΞΫηεͯ͠Έ͍ͯͩ͘͞ɻ BQQWJFXTUPEBZJOEFYIUNMFSC SFRVJSFMJCPNJLVKJSC DMBTT)FMMP$POUSPMMFS"QQMJDBUJPO$POUSPMMFS EFGJOEFY !PNJLVKJ0NJLVKJOFX FOE

    FOE BQQDPOUSPMMFSTUPEBZ@DPOUSPMMFSSC ˞͜ͷΑ͏ʹʮ֎͔ΒݟͨৼΔ෣͍Λม͑ͣʹίʔυ੔ཧ͢Δʯ ͜ͱΛϦϑΝΫλϦϯάͱݴ͍·͢ɻ SFRVJSFMJCPNJLVKJSC !PNJLVKJ0NJLVKJOFX Iࠓ೔ͷӡ੎I I!PNJLVKJOBNFI QϥοΩʔΧϥʔɿ!PNJLVKJMVDLZ@DPMPSQ QϥοΩʔͳํ֯ɿ!PNJLVKJMVDLZ@EJSFDUJPOQ ‏͜ͷߦΛ࡟আ
  29. ׬੒Ͱ͢ʂ ͓͔ͭΕ͞·Ͱͨ͠

  30. ͸΍͘ऴΘͬͨਓ͸ ɾ$PEFDBEFNZͷ3VCZฤΛ΍ͬͯΈΔ $PEFDBEFNZ͸ΦϯϥΠϯֶशαΠτͰ͢ɻ ࣮ࡍʹϒϥ΢β্Ͱ࣮ߦͯ͠౴͑͋ΘͤΛͰ͖Δͷ͕ศརɻ IUUQXXXDPEFDBEFNZDPNUSBDLTSVCZ ɾϛχπΫͷ3VCZೖ໳ฤΛ΍ͬͯΈΔ ϛχπΫ͸ΦϯϥΠϯֶशαΠτͰ͢ɻ ೔ຊޠ આ໌͕ͱͯ΋ஸೡͰΘ͔Γ΍͍͢Ͱ͢ɻ IUUQXXXNJOJUVLVOFU

  31. ‑໰୊จ ͜͜ʹίʔυΛॻ͘ Ͱ͖ͨΒ3VO‎ ݁Ռ͕දࣔ͞ΕΔ $PEFDBEFNZ

  32. None
  33. ߨٛࢿྉஔ͖৔ ߨٛࢿྉஔ͖৔Λͭ͘Γ·ͨ͠ɻ աڈͷࢿྉ͕%-Ͱ͖·͢ɻ IUUQTHJUIVCDPNIJUPUTVCBTIJSVCZMFDUVSF PS IUUQCJUMZSVCZMFDUVSF

  34. ࡶஊɾ࣭໰༻GBDFCPPLάϧʔϓ GBDFCPPLάϧʔϓΛ࡞Γ·ͨ͠ IUUQTXXXGBDFCPPLDPNHSPVQTIJUPUTVCBTIJSC ɾՃೖඇՃೖ͸ࣗ༝Ͱ͢ ɾՃೖඇՃೖ͸੒੷ʹؔ܎͠·ͤΜ ɾࢀՃऀҰཡ͸ެ։͞Ε·͢ ɾॻ͖ࠐΈ͸ࢀՃऀͷΈݟ͑·͢ ɾر๬ऀ͸ΞΫηεͯ͠ࢀՃਃ੥͍ͯͩ͘͠͞ ɾࡶஊɺ࣭໰ɺٞ࿦ͳͲԿͰ΋ؾʹͤͣͲ͏ͧʙ ɾ࣭໰ʹ౴͑ΒΕΔਓ͸౴͍͑ͯ͋͛ͯͩ͘͞

    ɾߨࢣਞ΋͓౴͑͠·͢ ɾೖͬͨΒܰࣗ͘ݾ঺հ͓Ͷ͕͍͠·͢