クラウドxスマフォ時代のRuby on Rails入門

クラウドxスマフォ時代のRuby on Rails入門

1. Ruby言語, Ruby on Railsの紹介
2. Ruby on Rails で簡単なWebアプリを作る
3. 出来たWebアプリをクラウドにデプロイ
4. Webアプリをスマフォ用ブラウザーに対応する
5.Webアプリをスマフォアプリに対応する
6. RSpec

7ec547b3208545bcb5e6c0f1feb732c7?s=128

裕美 吉田

July 23, 2014
Tweet

Transcript

  1. Ϋϥ΢υ͇εϚϑΥ࣌୅ ͷ3VCZPO3BJMTೖ໳ 

  2. ࠓ೔ͷ͓࿩  ࣗݾ঺հ 3VCZݴޠͷ঺հ 3VCZPO3BJMTͷ঺հ 3VCZPO3BJMTͰ؆୯ͳ8FCΞϓ ϦΛ࡞Δ 8FCΞϓϦΛΫϥ΢υʹσϓϩΠ 2

  3. ࠓ೔ͷ͓࿩  ΞϓϦΛεϚϑΥ༻ϒϥ΢βʔʹର Ԡ͢Δ 8FCΞϓϦΛεϚϑΥΞϓϦͱ࿈ ܞ͢Δ 3BJMTͱ5%% ͕࣌ؒ͋Ε͹ 3

  4. ࣗݾ঺հ

  5. ٢ా༟ඒ ٢ా༟ඒ :PTIJEB:VVNJ  ༗ݶձࣾ&:0⒏DF IUUQXXXFZP⒏DFDPN #MPHIUUQEIBUFOBOFKQZVVN 5XJUUFS!ZVVNJ 5

  6. աڈ େֶͷ޻ֶ෦ଔۀ ૊ࠐܥͷձࣾʹब৬ $"%ͷϕϯνϟʔاۀʹస৬ $"%ίΞ෦෼ͷ։ൃ ਤ໘؅ཧγεςϜ౳Ͱ4&ɾϚωʔδϝϯτΛ ܦݧ γϦίϯόϨʔΛ๚໰ͨ͠Γɺถࠃਓͱ࢓ࣄΛ ܦݧ 6

  7. &:0⒏DF ೥ʹಠཱ ։ൃ 8FC 3VCZPO3BJMT  J1IPOF ڭҭ ͓٬༷ͷ໰୊Λղܾ͢Δ*5ڭҭ 3VCZPO3BJMT

    J1IPOF 7
  8. &:0⒏DF։ൃ 8FC 8 w ΞδΞϦʔάΞΠεϗοέʔ wIUUQXXXBMIPDLZKQ wνʔϜɾબखͷ੒੷ूܭ w1FSMಠࣗϑϨʔϜϫʔΫ wΞϩϋύʔΫ wαʔϏεऴྃ

    w4/4 w+BWB4FBTBS wωοτγϣοϓ wIUUQXXXCPSPDPKQ w3BJMTK2VFSZ w34QFD$VDVNCFS w๖͑τʔΫ ੠༏ͱ4LZQF Ͱ͓࿩  wαʔϏεऴྃ w੠༏ͱͷձ࿩༧໿༧໿ w3BJMTK2VFSZ w34QFD
  9. &:0⒏DF։ൃ J1IPOF 9 ֆຊΞϓϦ J1IPOFJ1BE 5XFFUͳ͏ ແྉ ڭ͑ࢠ͕࡞ͬͨΞϓϦ

  10. &:0⒏DFڭҭ 10 ίʔε໊ ೔਺ ಺༰ ޮՌ අ༻ 3VCZPO3BJMTೖ ໳ίʔε ೔

    w3VCZݴޠೖ໳ w3VCZPO3BJMTೖ໳ w3VCZPO3BJMT࣮श w3VCZ3VCZPO3BJMTͷ֓ཁ͕ཧղͰ͖Δ wܦݧ๛ͳ։ൃऀͰ͋Ε͹ɺॻ੶౳Λࢀߟʹ 3VCZPO3BJMTͷ։ൃ͕࢝ΊΒΕΔ ສԁਓ ໊Ҏ্Ͱड ߨ͍ͩ͘͞ 3VCZPO3BJMTඪ ४ίʔε ೔ w3VCZݴޠೖ໳ɺ3VCZ࣮ફϓϩάϥϛϯά w3VCZݴޠ࣮श w3VCZPO3BJMTೖ໳ɺ3VCZPO3BJMT࣮ફ։ൃ w3VCZPO3BJMT࣮श w3VCZ3VCZPO3BJMT͕ཧղͰ͖Δ w3VCZPO3BJMT։ൃϓϩδΣΫτʹϓϩάϥ Ϛʔͱͯ͠ࢀՃͰ͖Δ ສԁਓ 3VCZPO3BJMTప ఈίʔε ೔ w3VCZݴޠೖ໳ɺ3VCZ࣮ફϓϩάϥϛϯά w3VCZݴޠ࣮श w3VCZPO3BJMTೖ໳ɺ3VCZPO3BJMT࣮ફ։ൃ w3VCZPO3BJMT࣮श w࣮༻ΞϓϦͷ։ൃԋश w3VCZ3VCZPO3BJMT͕ཧղͰ͖Δ w3VCZPO3BJMTΛ࢖ͬͨϓϩδΣΫτͷઃ ܭɾ։ൃ͕࢝ΊΒΕΔ ສԁਓ 3VCZPO3BJMT
  11. &:0⒏DFͷڭҭ 11

  12. ࣥච 12

  13. 3VCZ,BJHJͰεϐʔν ੒ޭ͢Δ3VCZڭҭͷϓϥΫςΟεʯ 13

  14. 3VCZ8PSME$POGFSFODF ʰ3VCZ։ൃऀΛ૿΍ͨ͢Ίͷڭҭʹ͍ͭ ͯʵ೥ؒͷ3VCZڭҭͰಘͨ஌ݟʱ 14

  15. 8FCϝσΟΞ΁ͷࣥච 15

  16. 3VCZݴޠͷ঺հ

  17. 3VCZݴޠ ೔ຊਓ։ൃऀ·ͭ΋ͱΏ͖ͻΖࢯʹ Αͬͯ։ൃ͞ΕͨϓϩάϥϜݴޠɻ ੈքதͰ࢖ΘΕ͍ͯΔɻ ೥ΑΓΦʔϓϯιʔεͱͯ͠ެ ։ɻ -JTQ 4NBMMUBML 1FSMͳͲաڈͷݴޠ ͷྑ͍෦෼Λόϥϯεྑ͘औΓೖΕͯ

    ͍Δɻ 17 ࣸਅ͸XJLJQFEJBΑΓ
  18. ओཁͳݴޠͷྺ࢙ͱؔ࿈ 18

  19. 3VCZݴޠͷΩʔϫʔυ 19 ϓϩάϥϛϯάΛָ͘͢͠Δݴޠ ·ͭ΋ͱΏ͖ͻΖஶʮΦϒδΣΫτࢦ޲εΫϦϓτݴޠ3VCZʯΑΓ ͪΐͬͱେ͛͞ʹදݱ͢Δͱɺ3VCZͷڀۃ ͷ໨త͸ɺ༗ݶͷਓੜʹ͓͍ͯϓϩάϥϛ ϯάͷָ͍͠෦෼ʹͰ͖Δ͚ͩूதͰ͖Δ Α͏ʹॿ͚Δ͜ͱͰ͢ɻ

  20. 3VCZॲཧܥ .3* $3VCZ ɿ·ͭ΋ͱࢯ͕ͭͬͨ͘ݩ૆ +3VCZɿ+BWBͰ࡞ΒΕ+7.্Ͱಈ࡞͢Δ 3VCJOJVTɿ3VCZ --7.Ͱ࡞ΒΕͨॲཧܥ *SPO3VCZɿ/&5؀ڥͰಈ࡞͢Δ .BD3VCZɿ.BD049ʹಛԽͨ͠ॲཧܥ N3VCZ૊ΈࠐΈ༻3VCZ

    αϒηοτ  3VCZ.PUJPOJ04։ൃ༻3VCZίϯύΠϥʔ 20
  21. 3VCZͷόʔδϣϯ 9ɿੲʑ 9ɿաڈ ࡫ాߒҰࢯͷ࡞ͬͨ7.ΛίΞʹ ࠾༻͠ߴ଎Խ ଟݴޠ ./ Խ 3VCZ4QFD 3VCZඪ४࢓༷

     9ݱࡏ 21
  22. 3VCZPO3BJMT։ൃ؀ڥͷબ୒ 22 3BJMT)PTUJOH IUUQSBJMTIPTUJOHDPN ΑΓ 3VCZɺ3VCZPO3BJMTڞʹ6OJYจԽʹࠜ͟͠ ͓ͯΓɺҰ෦ͷϥΠϒϥϦʔ͸8JOEPXTͰ͸ ಈ͔ͳ͍ 8JOEPXTͰ΋جຊͷֶशఔ౓ʹ͸࢖͑Δ

  23. 3VCZͷΠϯετʔϧ .BD -JOVY DPOpHVSF NBLF NBLFJOTUBMM SCFOWෳ਺όʔδϣϯͷ੾Γ׵͑ 8JOEPXT IUUQSVCZJOTUBMMFSPSH 7.Λ࢖͍-JOVYΛΠϯετʔϧ

    23
  24. 3VCZ 3BJMT Πϯετʔϧ৘ใ IUUQSFENJOFFZP⒏DFOFU QSPKFDUTSBJMTXJLJ ࣌ʑߋ৽  IUUQRJJUBDPN ݹ͍هࣄ͸஫ҙ 

    IUUQTUBDLPWFSqPXDPNτϥϒ ϧରࡦʹ͸͓קΊ 24
  25. 3VCZݴޠ௒ೖ໳

  26. ಈతϓϩάϥϛϯάݴޠ ίϯύΠϧ౳͸ແ͘ɺ௚͙ʹ࣮ߦͰ ͖Δ JSCϓϩάϥϜΛॻ͔ͳͯ͘΋ 3VCZΛࢼͤΔίϚϯυ 26 % irb! > 2

    + 3! => 5
  27. ಈతܕ෇͚ σʔλʹܕ͕͋Δ͕ɺม਺ʹ͸ܕ͕ͳ͍ ม਺ͷએݴ͸ෆཁ 27 a = 1! pus a! a

    = “ABC”! puts a! a = [1,2,3]! puts a
  28. σʔλ ଞͷݴޠͱಉ͘͡ ੔਺ɺ࣮਺ɺจࣈྻʜ ഑ྻɺϋογϡʜ γϯϘϧ OBNF ໊લࣗ਎Λද͢σʔλ ϋογϡͷΩʔͱͯ͠ྑ͘࢖ΘΕΔ 28

  29. ࣜ ଞͷݴޠͱ΄΅ಉ͡ 29 a = 2 + (3 * 4)!

    s = “abc” + “def”! b = a > 20! x += 3! n++ ++ɺ-- ͸ແ͍
  30. ੍ޚจ จ๏͸ҧ͏͕ߟ͑ํ͸ಉ͡ ؆ܿͳจ๏ 30 if a > 0! b =

    1! else! b = 0! a = -a! end s = 0! while n > 0! s = s + n! n = n - 1! end
  31. ؔ਺ ϝιου ؆ܿͳจ๏ 31 def fact(n)! if n == 0!

    1! else! fact(n - 1) * n! end! end n = fact(5)! m = fact 4
  32. ΦϒδΣΫτࢦ޲ 32 จ๏͸ҟͳΔ͕ɺجຊ͸+BWB౳ͱ΄΅ಉ͡ class TwoNumber! def initialize(a, b)! @a =

    a; @b = b! end! def add! @a + @b! end! end tw = TwoNumber.new(3, 4)! a = tw.add()
  33. ͨͩ͠ɺ+BWBͱҧ͏ͱ͜Ζ΋͋Δ શ͕ͯΦϒδΣΫτ ΦʔϓϯΫϥε NJYJO NPEVMF 33 ΦϒδΣΫτࢦ޲

  34. શ͕ͯΦϒδΣΫτ ੔਺΋ΦϒδΣΫτ 34 i = 123! s = i.to_s()! s

    = String.valueOf(i);
  35. طଘͷΫϥεʹϝιουΛ௥Ճɾม ߋͰ͖Δ 35 ΦʔϓϯΫϥε class String! def double! self *

    2! end! end
  36. ࣮૷Λڞ༗ग़དྷΔ 36 NJYJO module Double! def double! self * 2!

    end! end class String! include Double! end! class Number! include Double! end 3.double # => 6! “ab”.double # => “abab”
  37. ࣗ༝౓͕ߴ͍ ϝλϓϩάϥϛϯά %4-  ϞϯΩʔύον ΦʔϓϯΫϥε͸΍΍ةݥͳͷͰ SFpOFNFOUTͰରԠ 37 ΦϒδΣΫτࢦ޲

  38. ؔ਺ܕݴޠ͔ΒͷӨڹ ΠςϨʔλ ϒϩοΫ શͯͷࣜɺจ͕஋Λ࣋ͭ ஗ԆධՁ 38

  39. ΠςϨʔλʔ &OVNFSBCMF 39 a = [1,2,3,4]! b = []! for

    n in a! if n > 2! b << n ! end! end a = [1,2,3,4]! b = a.select {|n| n > 2}
  40. ϒϩοΫ 40 def times(n)! for i in 1..n! yield(n)! end!

    end > times(3) {|n| puts n }! 1! 2! 3
  41. υΩϡϝϯτ ҉ه͢Δඞཁ͸͋Γ ·ͤΜ͕ɺҰ౓શͯ ໨Λ௨͓ͯ͘͠ͱྑ ͍ͱࢥ͍·͢ɻ 41

  42. ϥΠϒϥϦʔ ૊ΈࠐΈϥΠϒϥϦʔ ఴ෇ϥΠϒϥϦʔ 3VCZ(FNT 42

  43. 3VCZPO3BJMTͷ঺հ

  44. 3VCZPO3BJMTͱ͸ Φϥϯμͷ%BWJE)FJOFNFJFS )BOTTPO %)) ࢯʹΑͬͯ࡞ΒΕͨ ϑϨʔϜϫʔΫɻ ൴͕ڞಉܦӦ͢Δձࣾ#BTFDBNQ TJHOBMT ͷαʔϏε։ൃ༻ʹ࡞ͬͨ ΋ͷΛΦʔϓϯιʔεͱͯ͠೥ʹ

    ެ։ɻ +BWBͷഒͷੜ࢈ੑͱ͍͏ηϯηΠγϣ φϧͳΩʔϫʔυͰ࿩୊ʹͳΔɻ 44 ࣸਅ͸XJLJQFEJBΑΓ
  45. 45 ʮ++6($SPTT$PNNVOJUZ$POGFSFODF'BMMͷʰ+BWB͔Β3VCZ΁ʱɾΞϯυɾφ΢ʯ ΑΓɺҰ෦Ճච Patterns of Enterprise Application Architecture Extreme Programming

    Explained -- Embrace Change ୡਓϓϩάϥϚʔ γεςϜ։ൃͷ৬ਓ͔Β໊ঊ΁ͷಓ 3VCZPO3BJMTͷഎܠ Programming Ruby: The Pragmatic Programmer's Guide
  46. &:0⒏DF Ͳ͏ͯ͠3VCZ͸ੈքͰ࢖ΘΕΔ Α͏ʹͳͬͨͷ͔ʁ 46 Dave Thomas ӳޠͷ OFXTHSPVQ ΍XFC

  47. 3VCZPO3BJMTͷΩʔϫʔυ ৘ใͷॏෳ͸มߋͷࠔ೉͞Λ૿େ͠ಁ໌ ੑΛݮগͤ͞ɺෆҰகΛੜ͡ΔՄೳੑʹ ͭͳ͕ΔͨΊɺॏෳ͢Δ΂͖Ͱͳ͍ɻ 47 %3: %POUSFQFBUZPVSTFMG

  48. 3VCZPO3BJMTͷΩʔϫʔυ ઃఆΑΓ΋ن໿ ϧʔϧʹଇΔࣄͰɺ൥ࡶͳઃఆΛॻ͔ͳ ͯ͘΋Α͍ɻ 3BJMTͱ͍͏໊લʹ͸ʮ%))ͷෑ͍ͨϨʔ ϧʹ৐ͬͯߦ͚͹ߴ଎ʹΞϓϦ͕ߏஙग़ དྷΔʯͱ͍͏ҙຯ͕ࠐΊΒΕ͍ͯΔɻ 48 $P$ $POWFOUJPOPWFS$POpHVSBUJPO

  49. 3VCZPO3BJMTͷ࣮૾ 49

  50. ຊ౰ʹ+BWBͷഒͷੜ࢈ੑʁ ࡞੒͢ΔΞϓϦέʔγϣϯͷछྨ΍ ن໛ʹ΋ΑΓ·͕͢ɺ̎ʙ̑ഒ͘Β ͍ͱݴΘΕ͍ͯ·͢ɻ ·ͨɺ+BWB ୈҰੈ୅ϑϨʔϜϫʔΫ ͱ 3VCZPO3BJMT ୈೋੈ୅ϑϨʔϜϫʔΫ 

    Ͱ͸։ൃͷελΠϧ΋ҧ͍·͢ɻ 50
  51. +BWB ୈҰੈ୅ϑϨʔϜϫʔΫ ͷ ։ൃελΠϧ ΞʔΩςΫνϟʔͷܾఆ ߴ͍ٕज़εΩϧ ࣮຿ܦݧ ઃܭηϯε 51 ࡉ෼Խ͞Εͨ࢓༷

    ͷ࣮૷ ௿͍ٕज़εΩϧ ୯७࡞ۀత ΞʔΩςΫτ ϓϩάϥϚʔ ϓϩάϥϚʔ ϓϩάϥϚʔ ϓϩάϥϚʔ ϓϩάϥϚʔ ϓϩάϥϚʔ ϓϩάϥϚʔ ϓϩάϥϚʔ ϓϩάϥϚʔ ϓϩάϥϚʔ ϓϩάϥϚʔ ϓϩάϥϚʔ ϓϩάϥϚʔ ϓϩάϥϚʔ ϓϩάϥϚʔ ϓϩάϥϚʔ ϓϩάϥϚʔ ϓϩάϥϚʔ ϓϩάϥϚʔ ϓϩάϥϚʔ ࢓༷ॻ น
  52. 3VCZPO3BJMTΛ࢖ͬͨඪ४ తͳ։ൃελΠϧ 52 ϓϩάϥϚʔ ϓϩάϥϚʔ ϓϩάϥϚʔ ϓϩάϥϚʔ ࢓༷ॻ େ͖͘ͳ͍νʔϜ தڃҎ্ͷٕज़εΩϧ

    શһͰΞʔΩςΫνϟʔ Λܾఆ શһͰ࣮૷ গਓ਺ͳΒॳڃऀͷࢀՃ ΋̤̠
  53. ॳ৺ऀͰ΋࢖͍͜ͳͤΔͷʁ ΄΅/0 3VCZ΋3VCZPO3BJMT΋࢖͍͜ͳ͢ ʹ͸தڃऀҎ্ͷεΩϧ͕ඞཁͰ͢ɻ 3BJMT͸ΦϒδΣΫτࢦ޲΍ϝλϓϩά ϥϛϯά͕ଟ༻͞Ε͓ͯΓɺྑ͍γε ςϜΛ࡞Δͷ͸ॳ৺ऀͰ͸೉͍͠ɻ 53

  54. +BWB͔Β3VCZ΁ ʮ+BWB͔Β3VCZ΁ʯͱ͍͏ ຊ͕຋༁͞Εͨɻ ৽͍ٕ͠ज़ͷੜΈग़͞ΕΔϓ ϥοτϑΥʔϜ͕+BWB͔Β 3VCZ΁ͱҠΓͭͭ͋Δɻ "KBY ϚογϡΞοϓ 3&45 #%%

    54 ʮ+BWB͔Β3VCZ΁ʯ ΦϥΠϦʔɾδϟύϯ
  55. +BWB͸ഇΕͯશͯ3VCZʹͳͬ ͯ͠·͏ͷ͔ʁ 55 Java Ruby ͔͍ͨɺ҆ఆ͕ٻΊΒΕΔ ॊೈɺૉૣ͍มԽ͕ٻΊΒΕΔ Java Ruby ΋ͪΖΜ/0

  56. 3VCZPO3BJMTͷόʔδϣϯΞοϓ ʙ೥ʹҰ౓ͷϝδϟʔόʔδϣϯ Ξοϓ ͦͷؒɺ਺ճͷϚΠφʔΞοϓσʔτ ྑ͘ͳΔͷͰ͋Ε͹ɺଟগͷޓ׵ੑ͸ ແࢹ 56

  57. 3VCZPO3BJMTೖ໳

  58. ࠓճͭ͘ΔΞϓϦ ը૾4/4ͷΑ͏ ͳ΋ͷ 58

  59. ίϚϯυ ίϚϯυ ͱΤσΟλʔ Λ࢖͍։ൃ IFMQΛࢦఆ͢Ε͹ϔϧϓ͕දࣔ͞ΕΔ ओͳίϚϯυ SBJMTίʔυ਽ܗ࡞੒ɺ࣮ߦ SBLF։ൃ࣌ͷࡶ༻  CVOEMFHFNϥΠϒϥϦʔͷ؅ཧ

    59
  60. ։ൃͷྲྀΕ  SBJMTOFXͰϓϩδΣΫτΛ࡞੒  SBJMTHͰίʔυͷ਽ܗΛ࡞੒  SBLFECNJHSBUFͰςʔϒϧΛ࡞੒  SBJMTTͰαʔόʔΛىಈ 

    ίʔυͷมߋɾ௥Ճ  ΁໭Δ 60
  61. SBJMTίϚϯυ rails new ϓϩδΣΫτ! ৽نϓϩδΣΫτͷ࡞੒ rails g ςʔϒϧ ΧϥϜ:ܕ …!

    ςʔϒϧͱͦΕΛѻ͏ίʔυͷ࡞੒ rails s! αʔόʔͷىಈ rails c! ։ൃίϯιʔϧ 61
  62. 62 BQQϓϩάϥϜɺৄࡉ͸࣍ϖʔδ CJO։ൃπʔϧ MJCϥΠϒϥϦʔ DPOpHઃఆ ECσʔλϕʔεؔ܎ QVCMJDελςΟοΫͳ)5.-ͳͲ TQFD UFTUςετίʔυ WFOEPS͍Ζ͍Ζ

    ྺ࢙తͳཧ༝  MPHϩάϑΝΠϧ UNQҰ࣌తͳϑΝΠϧͳͲ (FNpMFHFNϥΠϒϥϦʔͷ؅ཧ ΞϓϦͷσΟϨΫτϦʔߏ଄
  63. 63 BQQͷσΟϨΫτϦʔߏ଄ BTTFUT$44 +BWB4DSJQU ը૾  DPOUSPMMFSTίϯτϩʔϥ IFMQFSTϔϧύʔɺදࣔͷิॿ NPEFMTϞσϧ NBJMTϝʔϧίϯτϩʔϥ

    WJFXTදࣔςϯϓϨʔτ MBZPVUTදࣔͷ࿮૊Έ ίϯτϩʔϥ୯ҐͷςϯϓϨʔτ
  64. .7$ .PEFMۀ຿ϩδοΫɺܭࢉͳͲɺॲཧͷຊ࣭ 7JFXදࣔ $POUSPMॲཧͷྲྀͷ੍ޚ 64

  65. ϚΠάϨʔγϣϯNJHSBUJPO 3BJMTͰ͸ςʔϒϧͷ࡞੒ɾมߋ΋ίʔυͱ ͯ͠؅ཧ͍ͯ͠Δ SBLFίϚϯυͰϚΠάϨʔγϣϯͷऔফ΍ ࠶࣮ߦ͕ग़དྷΔ 65 class CreatePosts < ActiveRecord::Migration!

    def change! create_table :posts do |t|! t.string :name! t.string :photo! t.text :caption! ! t.timestamps! end! end! end
  66. 3&45GVMͳίϯτϩϥʔ 63-͸ϦιʔεΛݱ͢ ૢ࡞͸ϝιου (&5 1045 1"5$) %&-&5& Λ࢖͏ SBLFSPVUFTίϚϯυͰදࣔ 66

    ૢ࡞ ϝιου 63- ॲཧ Ұཡ (&5 IUUQTFSWFSUPEPT JOEFY औಘ (&5 IUUQTFSWFSUPEPT TIPX ߋ৽ 1"5$) IUUQTFSWFSUPEPT VQEBUF ొ࿥ 1045 IUUQTFSWFSUPEPT DSFBUF ࡟আ %&-&5& IUUQTFSWFSUPEPT EFTUSPZ
  67. υΩϡϝϯτ ӳޠͰ͕͢׳ΕͯԼ ͍͞ FYBNQMFTͷίʔυ Λ࠷ॳʹಡΉͱྑ͍ ͱࢥ͍·͢ 67

  68. 3BJMTΞϓϦͷσόοΫ ΤϥʔϝοηʔδΛ͔ͬ͠ΓಡΉ ϩάϑΝΠϧΛಡΉ ϩάϑΝΠϧʹσόοΫ༻৘ใΛॻ ͖ग़͢MPHHFSEFCVH B  SBJMTDPOTPMFͰࢼ͢ɻ 68

  69. 3BJMTͷศརͳػೳ ೖྗσʔλͷνΣοΫWBMJEBUJPO ؔ࿈͢Δςʔϒϧͷࢀর ϔϧύʔ DBMMCBDL CFGPSFBDUJPO 69

  70. ςʔϒϧͷؔ࿈ 3BJMTͷϞσϧ͸ؔ࿈Λѻ͏ࣄ͕ग़དྷ·͢ ͜͜Ͱ͸VTFSTQPTUTʹ̍ɿଟͷؔ܎Λهड़ 70 class User < ActiveRecord::Base! has_many :posts!

    end class Post < ActiveRecord::Base! belongs_to :user! end
  71. ࠃࡍޠԽJO JOUFSOBUJPOBMJ[BUJPOJO 3BJMT͸࠷ॳ͔ΒࠃࡍޠԽ͞Ε͍ͯΔ Τϥʔϝοηʔδ౳͸࠷ॳ͸ӳޠ͔͠ ೖ͍ͬͯͳ͍ ଟࠃޠΛѻ͏αΠτ΋࡞Γ΍͍͢ 71

  72. (FNϥΠϒϥϦʔ

  73. (FNϥΠϒϥϦʔ Ұൠతͳػೳ͸͢Ͱʹ(FNͱͯ͠ެ։͞ Ε͍ͯΔࣄ͕ଟ͍ (FNΛ୳͢ʹ͸SVCZUPPMCPY͕໾ཱͭ ͍͍ͨͯ(JU)VCʹஔ͍ͯ͋Δ ͪΌΜͱϝϯς͞Ε͍ͯΔ͔ɺྑ͍ίʔ υ͔ΛνΣοΫͨ͠ํ͕ྑ͍ 73

  74. (FNϥΠϒϥϦʔͷར༻ 74  (FNpMFʹϥΠϒϥϦʔΛࢦఆ  CVOEMFͰΠϯετʔϧ  SBJMTHͰઃఆͳͲ  

    αʔόʔͷ࠶ىಈ  ίʔυͷ௥Ճɾมߋ
  75. Α͘࢖͏(FN 75 (FN ػೳ ,BNJOBSJ Ұཡͷϖʔδϯά $BSSJFS8BWF ը૾ͳͲͷΞοϓϩʔυ 1BQFSDMJQ ը૾ͳͲͷΞοϓϩʔυ

    0NJOJ"VUI 5XJUUFS 'BDFCPPLͳͲͷΛ࢖͏ϩάΠϯೝূ %FWJTF ࣗલ%#Λ࢖͏ϩάΠϯೝূɺଟػೳ 3BJMT"ENJO 3%#σʔλͷ؅ཧը໘
  76. 6*

  77. 5XJUUFS#PPUTUBQ σβΠϯྗͷແ͍։ൃऀ Ͱ΋ࠓ෩ͳ8FC͕࡞Ε Δ$44 +4  5XJUUFSͷσβΠφʔ͕ ࡞੒ͨ͠ 3BJMTͰ௚͙ʹ࢖͑Δ(FN ͕͋Δ

    77
  78. $MPVE

  79. Ϋϥ΢υJTԿ 79

  80. Ϋϥ΢υͷ෼ྨ 4BB4 4PGUXBSFBTB4FSWJDF 1BB4 1MBUGPSNBTB4FSWJDF *BB4 )BB4  *OGSBTUSVDUVSFBTB4FSWJDF 80

    ਤ͸8JLJQFEJBΑΓ
  81. Ϋϥ΢υͷ෼ྨ ΞϓϦέʔγϣϯ $3. &31 .BJM 0⒏DF ϓϥοτϑΥʔϜ 04 3%# .JEEMFXBSF

    Πϯϑϥ $16 %JTL /FUXPSL 81 ਤ͸8JLJQFEJBΑΓ
  82. 4BB4 1BB4 *BB4 )BB4  Ϋϥ΢υͷ෼ྨ 82 ਤ͸8JLJQFEJBΑΓ

  83. )FSPLVͱ͸ ݩʑ3VCZPO3BJMTʹಛԽͨ͠ 1BB4ͩͬͨ ؆୯ʹΞϓϦΛ഑ஔͰ͖Δ ؆୯ʹεέʔϧͰ͖Δ ແྉτϥΠΞϧ "84Λ࢖͍ͬͯΔ 4BMFTGPSDFͷࢠձࣾ 3VCZ։ൃऀΛޏ͍ͬͯΔ .BU[ɺ࡫ాɺதా

    83
  84. )FSPLVσϓϩΠखॱ  IFSPLVπʔϧͷμ΢ϯϩʔυɾΠϯετʔϧ  (FNpMFͷमਖ਼ 3. bundle install! 4. heroku

    create! 5. git commit! 6. git push heroku master! 7. heroku run rake db:migrate 84
  85. "84౳΁ͷσϓϩΠखॱ 85  "84ʹαʔόʔΛ࡞੒  αʔόʔʹ3VCZ 3%#ʜͷΠϯετʔϧɻ ͕͜͜େมʂ࠷ۙ͸$IFG౳ͰࣗಈԽ͢Δ  DBQJTUSBOPͷΠϯεʔϧ

     DBQJTUSBOPͷઃఆϑΝΠϧ࡞੒ɾมߋ 5. git commit! 6. git push origin master! 7. cap deploy!  ্ख͘ߦ͔ͳ͚Ε͹ ΁໭Δ
  86. *BT4WT1BT4 )FSLVͷΑ͏ͳ1BT4Λ࢖͑͹Πϯ ϑϥܥΤϯδχΞΛޏΘͳͯ͘΋҆ ৺ͯ͠αʔϏεΛ্ཱͪ͛ΒΕΔɻ ͨͩ͠ɺ1BT4͸*BT4ΑΓίετ͕ ͔͔Δ 86

  87. .PCJMF'JSTU

  88. .PCJMF'JSTU εϚϑΥ΍λϒϨοτͷ਺͸1$Λ ௒͑ͨେ͖ͳࢢ৔ͳͬͨ 88 IUUQXXXTMJEFTIBSFOFU CHFCFBΑΓ

  89. εϚϑΥ΁ͷରԠํ๏ 8FCΞϓϦʹεϚϑΥ༻ͷ$44 +BWB4DSJQU Λ௥Ճ ωΠςΟϒΞϓϦΛ࡞Γ"1* +40/ Ͱ௨৴͢Δ 89

  90. ࠓճͭ͘ΔΞϓϦ 90 4BGBSJ XFC ωΠςΟϒΞϓϦ

  91. 5XJUUFS#PPUTUBQ Ϩεϙϯγϒ8FCσβΠϯ 91

  92. 3VCZPO3BJMTͱεϚϑΥ 3BJMT͸όʔδϣϯ ೥ ౰͔࣌Β 8FC"1*ɺϦονΫϥΠΞϯτ޲͚ͷ+40/ 9.-Ͱͷσʔλ΍ΓऔΓ͕ग़དྷ͍ͯͨ 92 αʔόʔ 3VCZPO3BJMT +40/

    9.- +40/ 9.-
  93. +40/ͷग़ྗ Ϩεϙϯε͸)5.-Ҏ֎ʹ+40/౳Λग़ྗͰ ͖Δ 93 <p>! <strong>Name:</strong>! <%= @post.user.name %>! </p>!

    <p>! <strong>Caption:</strong>! <%= @post.caption %>! </p> json.extract! @post, :id, :name, :caption TIPXIUNMFSC TIPXKTPOKCVJMEFS
  94. 3BJMT⁶J04ϥΠϒϥϦʔ 94 0CKFDUJWF3FTPVSDFࢮ๢ ଞʹ΋͍Ζ͍Ζʜ

  95. 5%% ը૾͸IUUQNFUBPIMPIOFUHPJOHUEEΑΓ

  96. 96 ίʔυͷ࡞੒ ςεςΟϯά NO YES ςετίʔυͷ࡞੒ ίʔυͷ࡞੒ NO YES ςετίʔυͷ࣮ߦ

    ઃܭ ઃܭ σόοΫ ैདྷͷ։ൃελΠϧ ̩̙̙ͷ։ൃελΠϧ ͜͜Λ܁Γฦ͢͜ ͱͰ։ൃΛਐΊΔ جຊతʹ͸ Ұํ޲ͷྲྀΕ ඞཁͳΒςετίʔ υͷ࡞੒ 0, 0, 5%%ςετۦಈ։ൃ
  97. 5%%ͷϝϦοτ ୹ظ໨ඪ͕͋ΓϞνϕʔγϣϯ্͕ ͕Δɺਐ௙͕෼͔Γқ͍ ϦϑΝΫλϦϯά͠΍͘͢ͳΔ ϑϨʔϜϫʔΫ౳ͷόʔδϣϯΞο ϓ͕༰қʹͳΔ τʔλϧͰ͸։ൃ࣌ؒΛ୹͘ग़དྷΔ 97

  98. 5%%ͷσϝϦοτ ࠷ॳ͸ςετΛॻ͘ͷ͕೉͍͠ ϓϩάϥϛϯάॳ৺ऀʹ͸ςετ͕ ॻ͚ͳ͍ ςετΛॻ͘ࣄ͕໨తʹͳΓ͕ͪ 98

  99. ςετͷॻ͖ํ ςετίʔυ͸  ςετσʔλͳͲςετͷ४උ  ςετର৅ͷ࣮ߦ  ݁ՌΛ֬ೝ ·ͣ͸ɺਖ਼ৗܥΛ̍ͭॻ͘ ઌਓͷॻ͍ͨςετίʔυΛֶͿ

    99
  100. ϦϑΝΫλϦϯά ίʔυͷվળ ϝϯςφϯεੑͷߴ͍ίʔυʹ͢Δ جຊతʹ͸࢓༷͸ม͑ͳ͍ ςετ͕͋Δͱ༰қʹग़དྷΔ 100 ը૾͸IUUQNFUBPIMPIOFUHPJOHUEEΑΓ

  101. 34QFD 3VCZ 3BJMT ͰΑ͘࢖ΘΕΔπʔϧ ίϯύΫτͰ൑Γқ͍ςετ͕ॻ͚Δ STQFDSBJMTΛ࢖͏ͱNPEFM IFMQFS  DPOUSPMMFS WJFX

    NBJMFS SPVUFT  GFBUVSFTͷςετ͕ॻ͚Δ 101
  102. STQFDSBJMT࢖͍ํͷ͓קΊ NPEFMʹϩδοΫͷςετΛॻ͘ GFBUVSFTͰΞϓϦશମͷ؆୯ͳςετ Λॻ͘ 102

  103. ͖ͭͮʜ

  104. &:0⒏DF 3VCZݴޠೖ໳ॻ 1FSM 1ZUIPO౳ʹ׳Ε਌͠ΜͰ͍ΔਓҎ֎͸ઈରʹ 3VCZͷೖ໳ॻΛಡΜͰԼ͍͞ɻ ࣮ࡍʹຊ԰͞ΜͰோΊܾͯΊͯԼ͍͞ɻ ຊΛಡΉ͚ͩͰͳ͘ɺઆ໌ʹग़ͯ͘ΔίʔυΛࢼ͠ ͨΓɺԋश໰୊ͷίʔυΛॻ͍ͯԼ͍͞ɻ 104 *4#/

    *4#/ *4#/
  105. &:0⒏DF 3VCZPO3BJMTೖ໳ॻ ·ͣ͸Ұ࡭3VCZPO3BJMTͷຊΛಡΉͷ͕ૣಓͰ͢ ࣗ෼ʹͱͬͯಡΈ΍ͦ͢͏ͳຊΛબͿͷ͕ॏཁͰ͢ ࢴͷॻ੶͸࠷৽൛ʹରԠͯ͠ͳ͍Ͱ͕͢Ձ஋͸͋Γ·͢ 105 *4#/ IUUQQSBHQSPHDPNCPPL SBJMTBHJMFXFCEFWFMPQNFOU XJUISBJMT

    IUUQUBUTV[JOFDPN CPPLTSBJMTUVUPSJBM
  106. ωοτ্ͷ৘ใ ೥Ҏ্લͷ৘ใ͸ݹ͍ͷͰ஫ҙʂ ৴པग़དྷΔ৘ใ IUUQTXXXSVCZMBOHPSHKB IUUQSVCZPOSBJMTPSH IUUQHVJEFTSVCZPOSBJMTPSH ༗༻ IUUQTUBDLPWFSqPXDPN IUUQRJJUBDPN 106

    ˡ͓קΊ
  107. ೔ຊޠͷϒϩά౳ʹ͸໾ʹཱͨͳ͍ ΋ͷ͕··͋Γ·͢ ݕࡧ্Ґʹ͋Δ৘ใͰ΋ྑ͘ͳ͍΋ ͷ΋͋Γ·͢ ۩ମྫ͸ޱ಄Ͱ 107 ωοτ্ͷ৘ใ

  108. ࠓ೔ͷ݁࿦ ӳޠॏཁ ৽͍ٕ͠ज़͸ӳޠͰ΍ͬͯདྷΔ ӳձ࿩͸ޙճ͠ɺಡΊΕ͹0, ׳ΕΔࣄ͕ॏཁ 108

  109. ͓͔ͭΕ͞·Ͱͨ͠ IUUQXXXFZP⒏DFDPN