Slide 1

Slide 1 text

1 SinatraΛ࢖ͬͯ ॳΊͯWebΞϓϦΛ࡞ͬͯΈͨ @shirotamaki 2021, 6, 29 (Tue) ɹRuby LTձ@ΦϯϥΠϯ ओ࠵ : ϢχʔΫϏδϣϯגࣜձ༷ࣾ ʮRubyΫοΩϯάʯ

Slide 2

Slide 2 text

˙΋͘͡ 2 • ࣗݾ঺հ • ࡞ΔϝχϡʔɺࡐྉͳͲͷ঺հ • ࡐྉʹ͍ͭͯਂງΓ • ࡞Γํ

Slide 3

Slide 3 text

˙ࣗݾ঺հ @shirotamaki ɹ ۄ৓ ࢤ࿠ ϑΟϤϧυϒʔτΩϟϯϓ32ظੜ Rubyྺ: 6ϲ݄ 3

Slide 4

Slide 4 text

˙RubyͰ࡞Δϝχϡʔ 4 JSONͱHashΛ࢖ͬͨSinatra࢈ ϝϞΞϓϦ

Slide 5

Slide 5 text

˙ࡐྉ * JSONϑΝΠϧ * HashΦϒδΣΫτ 5 ˙༻ҙ͢Δ΋ͷ • Ruby 3.0.0 • Sinatra

Slide 6

Slide 6 text

˙ௐຯྉ * params ϋογϡ ɹ * JSON.parseϞδϡʔϧؔ਺ * JSON.dumpϞδϡʔϧؔ਺ 6

Slide 7

Slide 7 text

˙ਂງΓ

Slide 8

Slide 8 text

˙Sinatraʢγφτϥʣ 8 Ruby੡ͷWebΞϓϦέʔγϣϯϑϨʔϜϫʔΫͰ͢ɻ هड़಺༰͕؆ܿͰ෼͔Γ΍͘͢ͱͯ΋͍ܰͷ͕ಛ௃Ͱ͢ɻ ͦͷͨΊɺখن໛ͳΞϓϦέʔγϣϯΛ࡞੒͢Δͷʹ ޲͍͍ͯ·͢ɻ

Slide 9

Slide 9 text

˙JSONʢδΣΠιϯʣ 9 JavaScript Object Notationͷུ ߏ଄Խͨ͠σʔλΛදͨ͢ΊͷςΩετϑΥʔϚοτͷҰछͰ͢ɻ JavaScript͚ͩͰͳ͘ɺଟ͘ͷϓϩάϥϛϯάݴޠ΍WebαʔϏε ʹରԠ͍ͯ͠·͢ɻ ઃఆϑΝΠϧ΍σʔλަ׵ͳͲΛ͢Δͱ͖ʹΑ͘࢖ΘΕ͍ͯ·͢ɻ ϑΝΠϧ໊͸ʮKTPOʯɹ ˞σʔλϕʔεͷ؅ཧ͸JSONϑΝΠϧΛར༻͠·͢ɻ ɹࠓճɺActiveRecord͸ར༻͠·ͤΜɻ

Slide 10

Slide 10 text

˙JSON͕ରԠ͍ͯ͠Δσʔλܕ 10 JSONʹ૊ΈࠐΈͰ༻ҙ͞Ε͍ͯΔσʔλܕ̒ͭ * ΦϒδΣΫτ * ഑ྻ * จࣈྻ * ਺஋ * ϒʔϦΞϯ * null

Slide 11

Slide 11 text

˙Hashʢϋογϡʣ 11 ϋογϡ͸ɺʮΩʔʯͱʮ஋ʯͷηοτͰσʔλΛ؅ཧ͢Δ ΦϒδΣΫτͷ͜ͱͰ͢ɻ ଞͷݴޠͰ͸ʮ࿈૝഑ྻʯʮࣙॻʯʮϚοϓʯͱݺ͹ΕͨΓ ͠·͢ɻ ӳޠͷHash͸ɺίϚ੾Ε೑ͱ໺ࡊΛᖱΊͨྉཧͷࣄΛࢦ͠ɺ ϋογϡυϏʔϑͷޠݯͰ΋͋Γ·͢ɻ

Slide 12

Slide 12 text

˙Hashͷ2ͭͷॻ͖ํ 12 ϋογϡϩέοτ ࢖ͬͨॻ͖ํ ϋογϡϩέοτΛলུͨ͠ॻ͖ํ

Slide 13

Slide 13 text

˙Ruby ΫοΩϯάελʔτʂ 13

Slide 14

Slide 14 text

14 ˙·ͣ͸ɺrequireͰԼ͝͠Β͑

Slide 15

Slide 15 text

˙৽نϝϞೖྗը໘ͷϧʔςΟϯά 15

Slide 16

Slide 16 text

˙ڞ௨͢ΔϨΠΞ΢τΛ·ͱΊΔ 16 index.erb new.erb

Slide 17

Slide 17 text

17 ˙formλάͰೖྗɾૹ৴ϑΥʔϜΛ࡞੒͢Δ

Slide 18

Slide 18 text

˙్தܦաɺHTMLΛϨϯμϦϯάʢը૾Λੜ੒ʣ 18

Slide 19

Slide 19 text

˙HashΛJSON΁ม׵͠ϑΝΠϧΛอଘ͢Δ 19 JSON Hash JSON.dump

Slide 20

Slide 20 text

˙JSONϑΝΠϧͱͯ͠ɺdbσΟϨΫτϦ΁อଘ͢Δ 20

Slide 21

Slide 21 text

˙ϝϞҰཡදࣔ༻ͷϧʔςΟϯά 21 JSON Hash JSON.parse

Slide 22

Slide 22 text

˙Ұཡදࣔ༻ͷerbΛ࡞੒͢Δ 22

Slide 23

Slide 23 text

˙πϦʔߏ଄ 23

Slide 24

Slide 24 text

˙URL΁ΞΫηεͯ͠ΈΔ 24

Slide 25

Slide 25 text

˙ग़དྷ্͕Γʂ 25

Slide 26

Slide 26 text

˙ࢀߟهࣄɾࢀߟॻ੶ 26 ϓϩάϥϛϯάݴޠ Ruby ϦϑΝϨϯεϚχϡΞϧ https:/ /docs.ruby-lang.org/ja/(ࢀর2021,6,28) Sinatra: README http:/ /sinatrarb.com/intro-ja.html/(ࢀর2021.6.28) ϦϒϩϫʔΫε ஶ/ߴڮ ੐ٛ ؂म/ʰεϥεϥಡΊΔ Ruby;Γ͕ͳϓϩάϥϛϯά ʱ/ΠϯϓϨεϒοΫε/2019೥ ޒेཛྷ๜໌ɼদԬߒฏ ஶ/ʰθϩ͔ΒΘ͔Δ Ruby ௒ೖ໳ʱ/ٕज़ධ࿦ࣾ/2018೥ ߴڮ੐ٛɺޙ౻༟ଂ ஶ/ʰͨͷ͍͠Rubyୈ6൛ʱ/SBΫϦΤΠςΟϒ/2019೥ ҏ౻३Ұ ஶ/ʰϓϩΛ໨ࢦ͢ਓͷͨΊͷRubyೖ໳ ݴޠ࢓༷͔Βςετۦಈ։ൃɾσόοάٕ๏·Ͱʱ/ٕज़ධ࿦ࣾ/ 2017೥ ࢁຊཅฏஶ/ ʰWebΛࢧ͑Δٕज़ɹHTTP, URI, HTML, ͦͯ͠RESTʱ/ٕज़ධ࿦ࣾ/2010೥

Slide 27

Slide 27 text

˙ϒϩά΍ͬͯ·͢ 27 ͸ͯͳϒϩά D IT YɹλϚΩ޻຿ళͷIT೔ه https:/ /shirotamaki.hatenablog.com/

Slide 28

Slide 28 text

͝ਗ਼ௌ͍͖ͨͩ͋Γ͕ͱ͏͍͟͝·ͨ͠