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

Railsの設計 〜コントローラの メタボを防げ〜 / rails-controller-design

Railsの設計 〜コントローラの メタボを防げ〜 / rails-controller-design

2020-01-30 Gotanda.rb #41のLT資料です!
『Railsの設計 〜コントローラの メタボを防げ〜』

https://gotanda-rb.connpass.com/event/162164/

A92d05c5da067dc28a32527430f762ca?s=128

WalkerSumida

January 30, 2020
Tweet

Transcript

  1. 3BJMTͷઃܭ ʙίϯτϩʔϥͷ ϝλϘΛ๷͛ʙ גࣜձࣾϚπϦΧ /PUJBࣄۀ੹೚ऀ݉4FOTFTϓϩμΫτϚωʔδϟʔ "ZVNV4VNJEB

  2. ࣗݾ঺հ

  3. גࣜձࣾ ϚπϦΧ 4FOTFT 4'"$3.  /PUJB &NBJM5SBDLJOH  3BJMTPS3FBDU ΤϯδχΞ

    ઈࢍืूதͰ͢ʂ
  4. w େֶߦ͖ͳ͕Β*5ϕϯνϟʔاۀͰ໿೥ؒ༗ঈΠϯλʔϯ w 1)1 .Z42- $BLF1)1 Y 8PSEQSFTT $ "41

    /&5 w ౦ࣳ৘ใγεςϜגࣜձࣾͰ೥ؒϔϧεέΞࣄۀʹैࣄ w 7#/&5 $ 0SBDMF%BUBCBTF w ̍ਓͰىۀ͠Α͏ͱࢼΈΔ͕ࣦഊ w 3VCZPO3BJMT 'VFM1)1 .Z42- "84 "OTJCMF w גࣜձࣾϚπϦΧʹΤϯδχΞೋਓ໨ͷ૑ۀϝϯόʔͱͯ͠+PJO w /PUJBࣄۀ੹೚ऀ݉4FOTFTϓϩμΫτϚωʔδϟʔ w 3VCZPO3BJMT "OHVMBS+4 .Z42- "84 ܦྺ
  5. ίϯτϩʔϥͷϝλϘ Λ๷͛

  6. w 41"ߏ੒ͷΞϓϦέʔγϣϯͷઃܭΛ૝ఆͯ͠࡞ΒΕͨ಺༰ w 3BJMT͸"1*ͱͯ͠ར༻͢Δ૝ఆ લఏ

  7. w ݻ༗ͷϢʔεέʔεΛຬͨͦ͏ͱ͢Δઃܭࢥ૝ w ͭͷίϯτϩʔϥʹϝιουΛੜ΍͠·͘Δ w ͭͷϝιου಺ͰΤϯυϙΠϯτΛ෼͚ͨ΄͏͕ྑ͍Α͏ͳ ॲཧͷ෼ذ͕ଟ਺ ίϯτϩʔϥͷϝλϘͷݪҼ܊

  8. ରࡦ͸3&45GVM"1*ʹ ͋Δ

  9. 3&45GVM"1*ʹԊͬͯ஧࣮ʹ։ൃΛͰ͖ͯΔʁ✋

  10. w ΞυϨεՄೳੑ "EESFTTBCJMJUZ  w ఏڙ͢Δ৘ใ͕63*Λ௨ͯ͠දݱͰ͖Δ͜ͱɻશͯͷ৘ใ͸63*Ͱදݱ͞ΕΔҰҙͳΞυϨεΛ࣋ͬ ͍ͯΔ͜ͱɻ w εςʔτϨεੑ 4UBUFMFTT

     w )551Λϕʔεʹͨ͠εςʔτϨεͳΫϥΠΞϯταʔόϓϩτίϧͰ͋Δ͜ͱɻηογϣϯ౳ͷ ঢ়ଶ؅ཧ͸ͤͣɺ΍ΓऔΓ͞ΕΔ৘ใ͸ͦΕࣗମͰ׬݁ͯ͠ղऍͰ͖Δ͜ͱɻ w ઀ଓੑ $POOFDUBCJMJUZ  w ৘ใͷ಺෦ʹɺผͷ৘ใ΍ ͦͷ৘ใͷผͷ ঢ়ଶ΁ͷϦϯΫΛؚΊΔ͜ͱ͕Ͱ͖Δ͜ͱɻ w ౷ҰΠϯλʔϑΣʔε 6OJGPSN*OUFSGBDF  w ৘ใͷૢ࡞ औಘɺ࡞੒ɺߋ৽ɺ࡟আ ͸શͯ)551ϝιου (&5ɺ1045ɺ165ɺ%&-&5& Λར༻͢ Δ͜ͱɻ ˞ࢀߟIUUQTRJJUBDPN/BHBPLB,FOJDIJJUFNTDFGDFEGCG 3&45ͬͯͳΜ͚ͩͬ
  11. w 3&45ͷݪଇʹଇͬͯߏங͞Εͨ8FCγεςϜͷ)551Ͱͷݺ ͼग़͠ΠϯλʔϑΣʔεͷ͜ͱ 3&45GVM"1*ͬͯͳΜ͚ͩͬ

  12. ͳͥ3&45GVM"1*͕ର ࡦʹͳΔͷ͔

  13. w ;BMBOEPʢβϥϯυΡʣ͕ग़͍ͯ͠Δ"1*ΨΠυϥΠϯʹҎԼͷΑ͏ͳݴ ༿͕͋Δ w l3&45GVM"1*͸ɺݻ༗ͷϢʔεέʔε͔Β͸੾Γ཭͞ΕɺΫϥΠΞϯ ταʔόΛૄ݁߹ʹ͢Δ܏޲ʹ͋Γ·͢z w IUUQTSFTUGVMBQJHVJEFMJOFTKBOFUMJGZDPNBQJEFTJHOQSJODJQMFT w 3&45Ͱߏ੒͞Εͨ0QFO"1*Ͱ͸ݻ༗ͷϢʔεέʔεʹԊͬͨ"1*Λग़͠

    ͍ͯΔͱ͜͸ݟͨ͜ͱ͕ແ͍ w 3&45GVM"1*͸ݻ༗ͷϢʔεέʔε͔Β੾Γ཭͞Ε͍ͯΔͱߟ͍͑ͯ ͍ 3&45GVM"1*͸ݻ༗ͷϢʔεέʔε͔Β੾Γ཭͢
  14. w ӈͷ5SFMMPͷϖʔδΛදࣔ͢Δͷ ʹ͸ɺ#PBSE -JTU $BSE "DUJWJUZ ͳͲͷ৘ใ͕ඞཁͰ৭ʑͳϦιʔ ε͕͋Δ͕ɺྫ͑͹ͭͷ"1*Λୟ ͘ͱશͯͷϦιʔε͕Ͱ͖ɺӈͷ ϖʔδΛදࣔ͢Δ͜ͱ͕Ͱ͖Δɺ

    ͱ͍͏ͷ͸ʮ͋ΔϖʔδΛ։ͨ͘ Ίͷ"1*ʯͱ͍͏͜ͱͰݻ༗ͷ ϢʔεέʔεʹͳΔ w ͜ΕΛ΍Δͱ૝૾Ͱ͖ΔΑ͏ʹί ϯτϩʔϥ͕ϝλϘʹͳΔ ݻ༗ͷϢʔεέʔεͷۃ୺ͳྫ
  15. w ઌఔͷ#PBSE -JTU $BSE "DUJWJUZͦΕͧΕͷϦιʔεΛऔಘ͢ ΔͨΊͷ"1*͕͋Δ w IUUQTEFWFMPQFSTUSFMMPDPNSFGFSFODFJOUSPEVDUJPO w ͱͯ΋៉ྷͳͷͰɺઃܭͰ೰Μͩͱ͖ʹΑ͘ݟΔ

    5SFMMP͸៉ྷͳ3&45GVM"1*
  16. w ίϯτϩʔϥͷॲཧΛϞσϧʹಀͯ͠ίϯτϩʔϥͷϝλϘΛ ճආ͢Δͷ͸ਖ਼͍͠ରࡦͰ͸ͳ͍ w ˠϞσϧ͕ϝλϘʹͳΓɺӅΕϝλϘʹͳΔ ؒҧͬͨରࡦ

  17. 3BJMTͰϝλϘʹͳΒͳ͍ͨ Ίͷίϯτϩʔϥͷॻ͖ํͱ ͸

  18. class ItemsController < ActionController::API # GET /items def index; end

    # GET /items/{id} def show; end # POST /items def create; end # PATCH /items/{id} def update; end # DELETE /items/{id} def destroy; end end ϝλϘʹͳΒͳ͍ͨΊͷίϯτϩʔϥͷॻ͖ํͱ͸
  19. *UFNͷ$47ҰׅܥͷॲཧΛೖΕ͍ͨͷͰϝιουΛ ௥Ճ͠Α͏

  20. class ItemsController < ActionController::API # GET /items def index; end

    # GET /items/{id} def show; end # POST /items def create; end # PATCH /items/{id} def update; end # DELETE /items/{id} def destroy; end # POST /items_bulk def bulk_create; end # ͜Ε͸΍Βͳ͍΄͏͕͍͍ # PATCH /items_bulk def bulk_update; end # ͜Ε͸΍Βͳ͍΄͏͕͍͍ end ϝλϘʹͳΔίϯτϩʔϥͷॻ͖ํ
  21. class ItemsController < ActionController::API # GET /items def index; end

    # GET /items/{id} def show; end # POST /items def create; end # PATCH /items/{id} def update; end # DELETE /items/{id} def destroy; end end class Bulk::ItemsController < ActionController::API # POST /bulk/items def create; end # PATCH /bulk/items def update; end end ϝλϘʹͳΓʹ͘ίϯτϩʔϥͷॻ͖ํ
  22. w ॳΊ͸׳Εͳ͍͔΋͠Εͳ͍͕ɺͲΜͳϦιʔε JUFN VTFS  QBZNFOU Ͱ͋ͬͯ΋ɺJOEFY TIPX DSFBUF VQEBUF

    EFTUSPZϝ ιουͰ࡞੒͢Δ w %))ࢯ͕ݴ͍ͬͯΔ w IUUQTQPTUEDDIPXEIIPSHBOJ[FTIJTSBJMTDPOUSPMMFST ίϯτϩʔϥͷॻ͖ํʹ౷ҰੑΛ
  23. ৭ʑͳαʔϏεͷ"1*Λ ݟ͍ͯΔͱڞ௨෦෼͕

  24. w ιʔτͷঢॱ߱ॱ w JEঢॱJUFNT TPSU JE w JE߱ॱJUFNT TPSUJE w

    ιʔτͷෳ਺ࢦఆ w JE߱ॱ OBNFঢॱJUFNT TPSUJE OBNF w ιʔτͷঢॱ߱ॱσϑΥϧτ஋ w JUFNT TPSUJEͱͨ͠৔߹ঢॱͱͳΔ ιʔτฤ
  25. w ౓ʹऔಘͰ͖Δσʔλ਺ͷ্ݶ w ্݅ݶJUFNT MJNJU w ݅໨͔Βͷऔಘ w ݅໨͔ΒJUFNT P⒎TFUMJNJU

    w ͷϨίʔυΛऔಘ w ݅໨͔ΒJUFNT QBHFMJNJU ϖʔδϯά
  26. w ݕࡧจࣈ͸JUFNT RIPHFIPHFͷΑ͏ʹRύϥϝʔλʹΘͨ ͢ w (JUIVCͷྫJTTVFT RJTJTTVFJTPQFOCVOEMFS ݕࡧ

  27. 3&45GVM"1*ͰΑ͘࢖༻͞Ε ΔઃܭΛ؆୯ʹ࣮ݱͰ͖Δ 3BJMTʹ૊ΈࠐΉHFNΛ࡞ͬͨ

  28. w 3&45GVM"1*ͷҰൠతͳ࢖༻ͷઢ ࿏ʹ৐Δͱ͍͏ҙຯΛࠐΊͯ TFOSPʹ w JUFNT TPSUJE OBNFͱϦΫΤε τΛ౤͛ΔͱίϯτϩʔϥͰݺͼ ग़͢QBSBNT<bTPSU`>ͷதΛɺ42-ͷ

    03%&3#:۟ʹม׵ w IUUQTHJUIVCDPN XBMLFSTVNJEBTFOSP w ελʔͱ͍͏ༀ෺Λ͍ͩ͘͞ TFOSPHFN
  29. w ίϯτϩʔϥΛϝλϘʹ͠ͳ͍ͨΊʹݻ༗ͷϢʔεέʔεΛຬ ͨͦ͏ͱ͢Δ"1*ͷઃܭࢥ૝͸΍Ί·͠ΐ͏ w ͭͷίϯτϩʔϥʹϝιουΛੜ΍͠·͘Δͷ͸΍Ί·͠ΐ ͏ w جຊతʹ͸JOEFY TIPX DSFBUF

    VQEBUF EFTUSPZҎ֎͸ͳΔ ΂͘࢖Θͳ͍Α͏ʹ͠·͠ΐ͏ w "1*ͷઃܭͰ೰ΜͩΒɺ৭ʑͳαʔϏεͷ0QFO"1*ͷ࢖༻ͳͲ Λࢀߟʹͯ͠Έ·͠ΐ͏ ·ͱΊ
  30. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ