銀座Rails#1_uuushiro.pdf

457a32224e6ad774f17406984047f9ac?s=47 uuushiro
September 20, 2018

 銀座Rails#1_uuushiro.pdf

457a32224e6ad774f17406984047f9ac?s=128

uuushiro

September 20, 2018
Tweet

Transcript

  1. RailsελʔτΞοϓ͕ ΍ͬͯΑ͔ͬͨ͜ͱ ۜ࠲Rails#1 2018.09.20 גࣜձࣾελϝϯ @uuushiro

  2. Copyright © stmn, inc. All rights reserved. Page !X ࣗݾ঺հ

    ϋϯυϧωʔϜ/ࢯ໊ @uuushiro / দ୩ ༐࢙࿕(·ͭͨʹ Ώ͏͠Ζ͏) 
 ग़਎
 ɹѪ஌ݝ ඌுѴࢢ (ݱॅॴ͸໊ݹ԰ࢢ)
 ੜ೥݄೔
 ɹ1994/02/01 (24ࡀ)
 ུྺ ɹ2016೥ 9݄ ελϝϯͰΠϯλʔϯ։࢝ ɹ2017೥ 1݄ ελϝϯʹೖࣾ (৽ଔୈҰ߸) Rails ver 5.0.0 ͔Β৮Γ·ͨ͠ Raisྺ2೥
  3. ձࣾ֓ཁ

  4. Copyright © stmn, inc. All rights reserved. Page Ԋֵͱࣾһ਺ !4

    ໊ ձһ਺ ࣾһ਺ ૑ۀ 56/"( ЌϦϦʔε ౦ژࢧࣾ ࢿۚௐୡ ԯԁ 56/"( ਖ਼ࣜϦϦʔε ໊ݹ԰ຊࣾ ΦϑΟεҠస େࡕࢧࣾ 3BJMT   3VCZ 
  5. ໊ݹ԰ຊࣾ

  6. ϫʔΫεϖʔε

  7. ࣄۀ

  8. ʮ૊৫ΤϯήʔδϝϯτڧԽʯʹಛԽͨࣾ͠಺SNSαʔϏε

  9. Copyright © stmn, inc. All rights reserved. Page ػೳ •

    λΠϜϥΠϯɺϓϩϑΟʔϧɺνϟοτ Λඋ͑ͨɺϑϧػೳͷSNSɻ͢΂ͯࣗࣾ։ൃɻ • ೚ҙͷ੍౓(౤ߘϑΥʔϜ)Λ࡞Δ͜ͱ͕Ͱ͖Δ (Google ϑΥʔϜ ͷߴػೳ൛)ɻ !9 גࣜձࣾελϝϯͰͷར༻෩ܠ
  10. Copyright © stmn, inc. All rights reserved. Page TUNAGͷٕज़ελοΫ !10

    /BUJWF 'SPOUFOE "QQMJDBUJPO .JEEMFXBSF *OGSBTUSVDUVSF .FUBCBT
  11. Copyright © stmn, inc. All rights reserved. Page TUNAGͷٕज़ελοΫ !11

    /BUJWF 'SPOUFOE "QQMJDBUJPO .JEEMFXBSF *OGSBTUSVDUVSF .FUBCBT ੈͷதͷศརͳαʔϏε͸ੵۃతʹར༻͠ɺ ࣗࣾͷڧΈʹूத͍ͨ͠
  12. RailsελʔτΞοϓ͕ ΍ͬͯΑ͔ͬͨ͜ͱ

  13. Copyright © stmn, inc. All rights reserved. Page ໨࣍ •ೖΕͯΑ͔ͬͨgem

    •࢖ͬͯΑ͔ͬͨπʔϧɾαʔϏε •औΓೖΕͯΑ͔ͬͨ։ൃελΠϧ !13
  14. ೖΕͯΑ͔ͬͨgem

  15. Copyright © stmn, inc. All rights reserved. Page aasm !15

    ঢ়ଶભҠ؅ཧΛαϙʔτͯ͘͠ΕΔgem
  16. Copyright © stmn, inc. All rights reserved. Page ෳࡶͳঢ়ଶભҠ͸؅ཧ͕೉͍͠ •TUNAGͰ͸Ϟσϧͷঢ়ଶ؅ཧ͸

    enum Ͱ؅ཧ͍ͯ͠Δ •ঢ়ଶભҠ͕ෳࡶԽ͢Δͱ؅ཧ͕େม •᜛ٞͷΑ͏ͳঝೝػೳ(ϫʔΫϑϩʔ) ΍ ECͷ஫จ؅ཧͳͲ !16 ։࢝ Ωϟϯηϧ ਃ੥த ঝೝࡁΈ ׬ྃ ٫Լ
  17. Copyright © stmn, inc. All rights reserved. Page aasmͷಛ௃ •DSLͰঢ়ଶભҠͷ੍໿Λ؆ܿʹهड़Ͱ͖Δ

    •ঢ়ଶભҠ࣌ʹ೚ҙͷίʔϧόοΫΛࢦఆͰ͖Δ •enum ͕ར༻Ͱ͖Δ •σϑΥϧτͩͱ aasm_state ΧϥϜΛ௥Ճ͢Δ !17
  18. Copyright © stmn, inc. All rights reserved. Page ίʔυྫ !18

    Մಡੑ͕ߴ͘ɺ ঢ়ଶભҠͷ੍໿Λ؅ཧ͠΍͍͢
  19. Copyright © stmn, inc. All rights reserved. Page ίʔυྫ !19

    Մಡੑ͕ߴ͘ɺ ঢ়ଶભҠͷ੍໿Λ؅ཧ͠΍͍͢ ಛఆͷঢ়ଶભҠͷίʔϧόοΫͷࢦఆ ͢΂ͯͷঢ়ଶભҠͷίʔϧόοΫࢦఆ FOVNར༻Մ
  20. Copyright © stmn, inc. All rights reserved. Page railroadyͱ૊Έ߹ΘͤΔͱ΋ͬͱخ͍͠ •ঢ়ଶભҠਤΛ࡞੒ͯ͘͠ΕΔ

    !20 CVOEMFFYFDSBJMSPBEZ"TQFDJGZBQQNPEFMTNPEFMSCcEPU5QOHP 3"*-4@3005EPDTUBUF@DIBOHFTNPEFMQOH
  21. Copyright © stmn, inc. All rights reserved. Page awesome_nested_set !21

    ActiveRecordͰπϦʔߏ଄Λѻ͑Δgem
  22. Copyright © stmn, inc. All rights reserved. Page RDBͰπϦʔߏ଄Λ࣮ݱ͍ͨ͠ •اۀ޲͚SNSͰ͸ɺ૊৫ਤ

    Λ ࣮૷͢Δඞཁ͕͋Δ •ྡ઀ϦετϞσϧ • ௚ۙͷ਌ͷΈΛࢀর • ΞϓϦέʔγϣϯଆͰ࠶ؼॲཧ •ܦ࿏ྻڍϞσϧ • ֎෦Ωʔ੍໿͕࢖͑ͳ͍ͨΊRDBͰ਌ࢠؔ܎ͷ੔߹ੑ͕อূͰ͖ͳ͍ •ೖΕࢠू߹Ϟσϧ !22 ͸͡Ί͸͜ΕΛ࠾༻͍ͯͨ͠
  23. Copyright © stmn, inc. All rights reserved. Page TUNAGʹ͓͚ΔπϦʔߏ଄ͷཁ݅ •πϦʔߏ଄ΛͨͲΔॲཧ͕ଟ͍

    •૊৫ ΍ ഑ଐ ͷߋ৽ස౓͸গͳ͍ •awesome_nested_set (ೖΕࢠू߹Ϟσϧ)Λ࠾༻ •ߋ৽ίετ͸ߴ͍͕ɺۙ઀ϦετϞσϧͱൺ΂ͯΫΤϦ਺Λ཈੍Ͱ͖Δ •left, rightΧϥϜ͚ͩͰͳ͘ɺparent_id΋࣋ͨͤΔͷͰɺࢠͷݕࡧޮ཰্͕͕Δ !23
  24. Copyright © stmn, inc. All rights reserved. Page the_sortable_treeͱ૊Έ߹ΘͤΔͱ؅ཧը໘΋؆୯ʹ࡞ΕΔ •υϥοάɾΞϯυɾυϩοϓͷGUIΛදࣔ͢ΔviewϔϧύʔΛఏڙͯ͘͠ΕΔ

    •࣌ؒΛ͔͚ͣʹɺػೳͷཁ݅Λୡ੒Ͱ͖ͨͷ͸ελʔτΞοϓॳظʹ͸ॿ͔ͬͨ !24
  25. Copyright © stmn, inc. All rights reserved. Page elasticsearch-model &

    elasticsearch-dsl !25 ElasticsearchΛRailsͰѻ͍΍͘͢͢Δgem
  26. Copyright © stmn, inc. All rights reserved. Page elasticsearch-model •ϞσϧͱElasticsearchͷ౷߹Λิॿ

    •searchϝιουͱimportϝιου͕ఆٛ͞ΕΔ •as_indexed_jsonΛΦʔόʔϥΠυ͢Δ͜ͱͰɺ import࣌ʹ࣮ߦ͞ΕΔσʔλͷม׵ ΛίϯτϩʔϧͰ͖Δ •ؔ࿈ςʔϒϧͷࢦఆ΋؆୯ʹ !26
  27. Copyright © stmn, inc. All rights reserved. Page elasticsearch-dsl •ΫΤϦΛDSLͰهड़Ͱ͖Δ

    •ؔ࿈͢Δෳ਺ͷϞσϧΛର৅ͱͨ͠ɺෳࡶͳݕࡧ͕Ͱ͖Δ •must: AND৚݅ •filter: AND৚݅ •should: OR৚݅ •must_not: NOT৚݅ !27
  28. Copyright © stmn, inc. All rights reserved. Page Alias Λར༻ͨ͠

    ΠϯσοΫεͷ࠶ߏங •ΠϯσοΫεʹΤΠϦΞε໊Λ෇༩͢Δ͜ͱ͕Ͱ͖Δɻ •ΤΠϦΞεͷࢀরઌΛ੾Γସ͑Δ͜ͱͰɺΠϯσοΫεΛೖΕସ͑Δ͜ͱ͕Ͱ͖Δɻ •ΤΠϦΞεͷ੾Γସ͑͸ɺΞτϛοΫʹߦΘΕΔ͜ͱ͕อূ͞Ε͍ͯΔɻ !28
  29. Copyright © stmn, inc. All rights reserved. Page xray-rails !29

    ϒϥ΢β্Ͱviewͷߏ଄ΛՄࢹԽͯ͘͠ΕΔ
  30. Copyright © stmn, inc. All rights reserved. Page !30

  31. Copyright © stmn, inc. All rights reserved. Page !31 ΫϦοΫ͢Δͱ

    ΤσΟλͰ֘౰ύʔγϟϧ Λ։͍ͯ͘ΕΔ ؔ࿈͢Δ$POUSPMMFS ΤσΟλͷઃఆ 3BJMTSPPUYSBZDPOpHΤσΟλઃఆϑΝΠϧ FEJUPS"QQMJDBUJPOT3VCZ.JOFBQQ$POUFOUT.BD04SVCZNJOFpMF
  32. Copyright © stmn, inc. All rights reserved. Page ඇಉظॲཧ: DelayedJob

    & Sidekiq •DelayedJob •Job ͕ DB Ͱ؅ཧ͞ΕΔͨΊɺModel ͷτϥϯβΫγϣϯʹ࿈ಈͤ͞Δ͜ͱ͕Ͱ͖Δɻ • assm ͱ૊Έ߹Θͤͯɺঢ়ଶભҠ ʹ࿈ಈͨ͠ඇಉظॲཧʹར༻͍ͯ͠Δɻ •Polling ͳͷͰଈԠੑ͸ແ͍ •DBͷΈͰ׬݁Ͱ͖Δ •sidekiq •ΠϕϯτυϦϒϯͰߴ଎ •PUSH௨஌ͷҰ੪ૹ৴ͳͲ୹ظؒͰେྔͷδϣϒΛࡹ͚Δ •redis ͕ඞཁ !32
  33. ࢖ͬͯΑ͔ͬͨπʔϧɾαʔϏε

  34. Copyright © stmn, inc. All rights reserved. Page imgix(ը૾ઐ༻CDN) •ը૾഑৴ઐ༻ͷCDNɻ

    •AWS S3 ্ͷը૾ΛϦΞϧλΠϜʹՃ޻͠ͳ͕Βɺߴ଎഑৴Ͱ͖Δɻ •΋ͱ΋ͱ͸ɺRails (ImageMagick) Ͱ Ճ޻͠ AWS CloudFront Ͱ഑৴͍ͯͨ͠ɻ •ॳճΞΫηε͕ಉ࣌ฒߦʹߦΘΕΔͱϨεϙϯε͕ѱԽ͢Δ͜ͱ͕͋ͬͨ •اۀ޲͚SNSͱ͍͏ಛੑ্ɺಋೖॳ೔ͳͲʹΞΫηε਺͕ूத͠ɺ
 ϨεϙϯελΠϜ͕ѱԽ͢Δ͜ͱ͕͋ͬͨ •imgixΛಋೖ͢Δ͜ͱͰɺWEBαʔόͷෛՙΛ΁Β͢͜ͱ͕Ͱ͖ɺ͞ΒʹαΠτεϐʔυ΋޲্ͨ͠ •small_light ͳͲͰը૾഑৴αʔόΛߏங͢ΔΑΓ΋͍҆͠ɺ଎͔ͬͨ •إݕग़ػೳͳͲɺػೳ΋͍͍ ײ͡ɻ !34
  35. Copyright © stmn, inc. All rights reserved. Page μογϡϘʔυը໘ !35

  36. Copyright © stmn, inc. All rights reserved. Page Bugsnag(ΫϥογϡϨϙʔτղੳπʔϧ) !36

  37. Copyright © stmn, inc. All rights reserved. Page Bugsnag(ΫϥογϡϨϙʔτղੳπʔϧ) !37

    EFWJTFΛ࢖͍ͬͯΔͱɺ ݱࡏೝূ͞Ε͍ͯΔϢʔβʔʹؔ͢Δ৘ใΛ ࣗಈతʹऔಘͯ͘͠ΕΔ
  38. Copyright © stmn, inc. All rights reserved. Page Bugsnag(ΫϥογϡϨϙʔτղੳπʔϧ) !38

    ϝʔϧΞυϨεɾ໊લͰߜΓࠐΊΔ
  39. Copyright © stmn, inc. All rights reserved. Page Bugsnag(ΫϥογϡϨϙʔτղੳπʔϧ) !39

    ΤϥʔͷΫϥεɾϑΝΠϧ໊ɾϝιου໊ͰߜΓࠐΊΔ
  40. Copyright © stmn, inc. All rights reserved. Page Bugsnag(ΫϥογϡϨϙʔτղੳπʔϧ) !40

    $POUSPMMFSɺϗετ໊ɺϦΫΤετ63-ɺϦΫΤετ*1ͰߜΓࠐΊΔ
  41. Copyright © stmn, inc. All rights reserved. Page SendGrid •ό΢ϯεॲཧΛ࣮૷͠ͳͯ͘΋ྑ͍ɻ

    •ϝʔϧαʔόʔΛ༻ҙ͠ͳͯ͘ࡁΉ •։෧཰ɺΫϦοΫ཰Λ೚ҙͷ୯ҐͰऔಘͰ͖Δ •sendgrid-rubyͰAPIΛར༻͕؆୯ʹ !41
  42. Copyright © stmn, inc. All rights reserved. Page μογϡϘʔυ !42

    ςετ
  43. Copyright © stmn, inc. All rights reserved. Page Mailtrap •։ൃ؀ڥ͔Βૹ৴͞ΕͨిࢠϝʔϧΛςετɺදࣔ͢ΔͨΊͷμϛʔSMTPαʔόʔ

    •։ൃதʹޡരϝʔϧΛૹΔ͜ͱ͕ͳ͘ͳΔ !43 ςετ
  44. Copyright © stmn, inc. All rights reserved. Page Metabase(BIπʔϧ) !44

    (6*Ͱϙνϙν͢Δ͚ͩ͋Δఔ౓ͷ ΫΤϦ͸ߏஙͰ͖Δ
  45. Copyright © stmn, inc. All rights reserved. Page Metabase(BIπʔϧ) !45

    (6*Ͱϙνϙν͢Δ͚ͩ͋Δఔ౓ͷ ΫΤϦ͸ߏஙͰ͖Δ 440ʹ΋ରԠ͍ͯ͠Δ
  46. औΓೖΕͯΑ͔ͬͨ։ൃελΠϧ

  47. Copyright © stmn, inc. All rights reserved. Page ఆظbundle update

    •Rails ͷ ਐԽʹ͍͍ͭͯ͘͜ͱ͕໨తɻ •ӨڹൣғΛಛఆ͠΍͘͢ɺݕূίετΛখ͘͢͞ΔͨΊʹɺि࣍ͰΞοϓσʔτɻ •ར༻͍ͯ͠Δgem΁ͷཧղΛਂΊΒΕΔ •CircleCI 2.0ͷϫʔΫϑϩʔػೳͰࣗಈԽ !47
  48. Copyright © stmn, inc. All rights reserved. Page ϨϏϡʔͷࣗಈԽ •ίʔσΟϯάελΠϧͳͲఆܕͳνΣοΫ͸ࣗಈԽ͢Δɻ

    •ઃܭ΍ΞϓϦέʔγϣϯϩδοΫͷϨϏϡʔʹ࣌ؒΛ͔͚Δɻ •rubocop, SiderΛಋೖ !48
  49. Copyright © stmn, inc. All rights reserved. Page RailsελʔτΞοϓ͕΍ͬͯΑ͔ͬͨ͜ͱ !49

    ೖΕͯྑ͔ͬͨHFN BBTN BXFTPNF@OFTUFE@USFF FMBTUJDTFBSDINPEFM FMBTUJDTFBSDIETM YSBZSBJMT EFMBZFE@KPC 4JEFLJR ೖΕͯྑ͔ͬͨπʔϧɾαʔϏε JNHJY #VHTOBH 4FOE(SJE .BJMUSBQ .FUBCBTF औΓೖΕͯྑ͔ͬͨ։ൃελΠϧ ఆظCVOEMFVQEBUF ϨϏϡʔͷࣗಈԽ
  50. Thank You For Your Attention