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

startupでもrails使うなら これだけはやっとけ的 tips集

startupでもrails使うなら これだけはやっとけ的 tips集

第一回スタートアップRails勉強会でLTしたスライドです

857128c64cd614520094f904c8eb79dc?s=128

Kazuhiro Serizawa

September 27, 2016
Tweet

More Decks by Kazuhiro Serizawa

Other Decks in Programming

Transcript

  1. startupͰ΋rails࢖͏ͳΒ ͜Ε͚ͩ͸΍ͬͱ͚త tipsू Kazuhiro Serizawa @seri_k
 Toreta, Inc. ೉қ౓ɿ௒͔ΜͨΜ Startup

    Rails #1
  2. About me • Kazuhiro Serizawa • github: :serihiro • work_at:

    • work: :serverside engineer(rails) • like: %i(ruby java erlang c)
  3. ࠓ೔࿩͢͜ͱ • StartupͰਓ͕গͳͯ͘΋͜Ε͚ͩ͸΍ͬͱ͍ ͨํ͕͍͍ͱࢥ͏tipsΛ̎ͭ࿩͠·͢ • ։ൃͱݴ͏͔ӡ༻ʹ͍ۙ࿩Ͱ͢

  4. ͦͷ1 ModelͷValidation͸࠷ॳ͔ΒೖΕΔ • webΞϓϦ։ൃॳظ
 
 ʮ͜ͷϞσϧ࢓༷ܾ·ͬͯͳ͍͔Β
 ɹ࠷ॳ͸Validationແ͠ͰͱΓ͑͋ͣೖΕΑ͏ɻ
 ɹ΋ͪΖΜશΧϥϜNullڐՄͩΑͶˑʯ

  5. class Reservation < ActiveRecord::Base end class CreateReservations < ActiveRecord::Migration def

    change create_table :reservations do |t| t.integer :restaurant_id, null: true t.integer :number, null: true t.datetime :from, null: true t.datetime :to, null: true t.integer :status, null: true t.timestamps null: false end end end ͦͷ1 ModelͷValidation͸࠷ॳ͔ΒೖΕΔ
  6. ͦͷ1 ModelͷValidation͸࠷ॳ͔ΒೖΕΔ • ͋Ε͔Β3೥͕ܦͬͨ… • ࠷ۙೖࣾͨ͠एऀᐌ͘
 ʮͳΜͰ͜ͷϞσϧҰ੾validation͍ͭͯͳ͍Μ͔͢ɻ
 Tableʹ΋NotNull੍໿ͳͯ͘Կ͢Δʹͯ͠΋nilνΣοΫ ඞਢ͡Όͳ͍͔͢ɻ
 ͢Ͱʹ9,000ສ݅΋Ϩίʔυ͋ͬͯࠓ͔Βmigration͢Δ

    ͷΊͪΌͪ͘Όେม͡Όͳ͍͔͢ɻΞϗͰ͔͢ઌഐɻʯ
  7. ͦͷ1 ModelͷValidation͸࠷ॳ͔ΒೖΕΔ • Ұ౓ෆద੾ͳσʔλΛ࡞ΓࠐΜͰ͠·͏ͱޙ͔Β ͷमਖ਼͕ͬͬͭ͘͘͢͢͝͝Β͍ʂʂ • ͋Δ೔ͷσϓϩΠ௚ޙɺ੍໿͕؇͔ͬͨ࣌୅ʹฆ Εͨมͳσʔλͷ͍ͤͰΤϥʔࡇΓʹͳͬͯ৭Μ ͳॴʹ౔Լ࠲ͯ͠ճΔӋ໨ʹͳΔʢ࣮࿩ʣ •

    ͔͠΋ͦ͏͍͏มͳσʔλ͕ೖ͍ͬͯΔͱ͍͏ࣄ ࣮͸࠷ॳ͔Β͍ͨਓؒʹ͔͠෼͔Βͳ͍ɻɻ
  8. ͦͷ1 ModelͷValidation͸࠷ॳ͔ΒೖΕΔ • ͳͷͰ • Validationͷ࢓༷͕ܾ·Βͳ͍΄Ͳཁ͕ܾ݅·Β ͳ͍͏ͪʹproductionʹ౤ೖ͠ͳ͍ • Tableʹ΋Not NullɺUnique੍໿͸Modelͷ

    validationͱซͤͯͪΌΜͱઃఆ͢Δ
 ˞uniqueness: true͸͍ͱ΋؆୯ʹ͢Γൈ͚Δ
  9. • productionͰΤϥʔग़ͯΔͷ์ஔ͢Δͱةͳ͍Α Ͷʔɺͱ͍͏ׂͱ౰ͨΓલͷ࿩ • ͔͠͠Τϥʔͷه࿥ɾ؅ཧ͸݁ߏΊΜͲ͍͘͞ • fluentdೖΕͯElasticSearchʹूΊͯkibanaͰݟ ΔʁES͸ࣗ෼ୡͰӡ༻͢ΔʁͲ͏΍ͬͯΤϥʔ͕ ى͖ͨ͜ͱΛ஌ΔʁͲ͏΍ͬͯΤϥʔΛ؅ཧ͢Δʁ ͦͷ2


    ͓खܰʹΤϥʔΛݟ͑ΔԽ͢Δ
  10. ͦͷ2
 ͓खܰʹΤϥʔΛݟ͑ΔԽ͢Δ https://bugsnag.com

  11. • railsͰൃੜͨ͠ྫ֎Λશ෦ه࿥ͯ͘͠ΕΔ ͦͷ2
 ͓खܰʹΤϥʔΛݟ͑ΔԽ͢Δ

  12. • github,slackͱͷintegration͕Մೳ ͦͷ2
 ͓खܰʹΤϥʔΛݟ͑ΔԽ͢Δ

  13. • ηοτΞοϓ͸gemೖΕͯgeneratorͰ initializerΛੜ੒͢Δ͚ͩ ͦͷ2
 ͓खܰʹΤϥʔΛݟ͑ΔԽ͢Δ

  14. ·ͱΊ • validation͸ޙ͔Β͖ͨएऀʹdisΒΕΔલʹ ೖΕ·͠ΐ͏ • bug͸؆୯ʹՄࢹԽͰ͖ΔͷͰ࠷ॳ͔ΒೖΕ ·͠ΐ͏

  15. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ • גࣜձࣾτϨλ͸αʔόʔαΠυ(rails)
 ΤϯδχΞืूதͰ͢ʂ
 WantedlyͰʮτϨλʯͰݕࡧ