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

Recent Rails movements in 15 minutes

Recent Rails movements in 15 minutes

Ruby on Rails及びその周辺技術は2021年になっても進化を続けています。特に近年は複数DB周りとフロントエンド関係で変化が顕著です。この発表ではそれらをまとめてご紹介します。

110cd4dcaed019b3bd9809e541afdeb6?s=128

Masafumi Okura

February 24, 2021
Tweet

Transcript

  1. ࠷ۙͷRailsࣄ৘Λ15෼Ͱ͓͞ Β͍ ୈ28ճΏΔ͸ͪ.it OKURA Masafumi, 2021-02-24

  2. ࣗݾ঺հ • ໊લɿେ૔խ࢙ʢ͓͓͘Β·͞;Έʣ • ॴଐɿϑϦʔϥϯε • ಘҙɿRubyͱRuby on Railsɺͪΐͬ͜ͱVim •

    ՝֎׆ಈɿ֤छొஃɺίϛϡχςΟӡӦʢܭ4ͭʣɺΧϯϑΝϨϯε ӡӦʢKaigi on RailsʣɺOSSʢgemΛܭ8ͭʣ
  3. 15෼

  4. ࠓ೔࿩͢͜ͱ • Rails 6.1Ͱೖͬͨػೳ • ߋʹਐΜͩෳ਺DBରԠ • ActiveModel::ErrorͷΦϒδΣΫτԽ • etc.

    • HotwireͱTurbo • StimulusReflexपล
  5. ࠓ೔ͷτʔΫ͸୭޲͚ʁ • ࠷ۙRailsΛ͋·Γ৮͍ͬͯͳ͍ਓ • RailsΛ৽نҊ݅Ͱ࠾༻͠Α͏͔໎͍ͬͯΔਓ • RailsͱϑϩϯτΤϯυͷؔ܎ੑʹ͍ͭͯ஌Γ͍ͨਓ

  6. Rails 6.1

  7. Rails 6.1 • 2020೥12݄ϦϦʔε • ໨ۄػೳ͸ਫฏγϟʔσΟϯάͳͲͷෳ਺DBରԠ • ActiveModel::Errorؔ܎ͷඇޓ׵ͳมߋ • ࡉ͔ͳվྑ

  8. Rails 6.1ʹ͓͚Δෳ਺DBରԠ • 6.0ͰύʔςΟγϣχϯά͕αϙʔτ͞Εͨ • 6.1Ͱ͸ਫฏγϟʔσΟϯά΋αϙʔτ͞Εɺ͞Βʹศརʹ • Ϟσϧ͝ͱʹҟͳΔDBʹ઀ଓ͢Δ͜ͱ΋Մೳʹ

  9. ActiveModel::Errorͷ௥Ճ • ैདྷ͸@model.errorsϝιου͸Τϥʔ৘ใؚ͕·ΕͨϋογϡΛฦ ͍͕ͯͨ͠ɺϋογϡͩͱѻ͍ͮΒ͞΍σʔλഁଛͷݒ೦΋͋ͬͨ • 6.1͔Β͸ɺ@model.errorsϝιου͸ActiveModel::ErrorΦϒδΣΫ τͷ഑ྻΛฦ͢Α͏ʹͳͬͨ • ৄࡉ͸ https://youtu.be/FGhZR4ns_tc

    ʢKaigi on RailsͰͷ࣮૷ऀͷ ൃදʣΛࢀর
  10. ࣍͸7.0ʹͳͬͨ • https://github.com/rails/rails/commit/ 1b455e2e9d6937d4107e19cb32e2f98aa08886b9 • ͳΜ͔Ͱ͔͍มߋ͕ೖΔΒ͍͠ʂ

  11. Hotwire

  12. Hotwire • https://hotwire.dev/ • RailsͷΦϦδφϧαʔϏεͰ͋ΔBasecampͷਓ͕ͨͪ࡞ͬͨɺ HTML Over The WireͷΦʔϓϯιʔε࣮૷ •

    Heyͱ͍͏ϝʔϧαʔϏεͰ࣮ઓ౤ೖࡁΈ • TurboɺStimulusɺStradaͷ3ͭͷίϯϙʔωϯτͰߏ੒͞ΕΔ • ଞݴޠͩͱLivewire΍Liveviewͱݺ͹ΕΔ΋ͷ͕ࣅ͍ͯΔΒ͍͠
  13. Turbo • JavaScriptͷهड़ྔΛ࠷খݶʹͭͭ͠ϢʔβʔମݧΛ޲্ͤ͞ΔͨΊ ͷϥΠϒϥϦ • DriveɺFramesɺStreamsɺNativeͷ4ͭͷίϯϙʔωϯτͰߏ੒͞Ε Δ • ͋Μ·ΓͪΌΜͱ৮Εͯͳ͍ͷͰղઆͰ͖ͳ͍…

  14. Stimulus • ܰྔͳJavaScriptϑϨʔϜϫʔΫ • TurboͰ͸଍Γͳ͍ͱ͖ʹStimulusͰJSΛॻ͘ɺͱ͍͏ΠϝʔδΒ͠ ͍ • CoCʢઃఆΑΓن໿ʣͷΑ͏ͳRailsͬΆ͍Ξϓϩʔν͕ಛ௃

  15. Strada • ະϦϦʔε • ϞόΠϧΞϓϦʹؔΘΔ΋ͷΒ͍͠

  16. StimulusReflex

  17. StimulusReflexʢҎԼ”SR”ʣ • https://docs.stimulusreflex.com/ • Hopsoftͱ͍͏ਓ͕ϝΠϯͰ։ൃ͍ͯ͠ΔΦʔϓϯιʔεͷRails޲͚ ϥΠϒϥϦ • WebSocketΛ׆༻ͯ͠HTMLΛॻ͖׵͑Δ • SPAͬΆ͍ΞϓϦΛJSΛॻ͔ͣʹ࡞ΕΔ͕ɺStimulusʹґଘ͍ͯ͠Δ

    • Djangoͱ͔Ͱಈ͔͍ͯ͠Δਓ΋͍ΔΒ͍͠…ʁ
  18. ༨ஊ • SRΛ࢖͍20෼ͰTwitterͬΆ͍ΞϓϦΛ࡞ΔϥΠϒίʔσΟϯά͕ۜ ࠲Rails#27ͰߦΘΕͨʢhttps://ginza-rails.connpass.com/event/ 193008/ʣ • ؆୯ͳը໘ಉظΛ࣮૷͍͚ͨͩ͠ͳΒ͜ΕͰ΋े෼Ͱ͸ͱ͍͏࣮ײ • SR͸ίϛϡχςΟ͕׆ൃʢDiscord͸1000ਓ௒͑ʂʣ •

    ࡞ऀ͔Β௚઀αϙʔτͯ͠΋Β͑Δ͔΋ʁ
  19. पลٕज़ • CableReadyɿSRͷج൫ɺWebSocketʹσʔλΛྲྀ͠ࠐΉ • FuturismɿRailsͷύʔγϟϧΛActionCableͰඇಉظͰϨϯμʔ͢Δ • OptimismɿRailsͷόϦσʔγϣϯͱΤϥʔͷϨϯμϦϯάΛϦΞϧ λΠϜͰߦ͏ • ViewComponentReflexɿViewComponentͱ͍͏GitHubࣾʹΑΔ

    ϏϡʔίϯϙʔωϯτϑϨʔϜϫʔΫͱSRΛ૊Έ߹ΘͤͨϥΠϒϥϦ
  20. HotwireͱSR͔Ϳͬͯͳ͍ʁ

  21. ͔ͿͬͯΔʂ

  22. HotwireͱSRͷকདྷ͸Ͳ͏ͳΔͷ͔ • Θ͔ΒΜʂ • Hotwire͸ActiveRecordͷCRUDίʔϧόοΫͱͷ૬ੑ͕ྑ͍ͷͱγ ϯϓϧͳͷ͕ڧΈͬΆ͍ • SR͸Morphͱ͍͏֓೦ʹΑΓԠ༻ൣғΛ޿͍͛ͯΔҹ৅ • ͕ͬͭΓ࢖͍ൺ΂ͯΈͨΘ͚Ͱ͸ͳ͍ͷͰ஌ݟ͕΄͍͠ͱ͜Ζ

  23. ·ͱΊ

  24. Rails 6.1 • ෳ਺DBରԠ͸͔ͳΓਐΜͩ • ErrorपΓͷඇޓ׵ʹ஫ҙ • ࣍͸Rails 7!

  25. HotwireͱSR • ͲͪΒ΋RailsϝΠϯʢগͳ͍JSʣͰSPAͬΆ͍ΞϓϦΛ࣮ݱ͢ΔͨΊ ͷπʔϧ • ࠓޙɺ྆ํ͕ྲྀߦΔͷ͔ɺͲͪΒ͔͕γΣΞΛऔΔͷ͔ɺͲͪΒ΋࢖ ΘΕͳ͍ͷ͔ɺ·ͩ୭ʹ΋Θ͔Βͳ͍ • ؾʹͳΔਓ͸ཁνΣοΫͩʂ