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

kawasakirb053

227427c9146ca16f86f78a6a021105ec?s=47 masaru-tech
October 26, 2017
4.6k

 kawasakirb053

辛かった愚痴スライドです

227427c9146ca16f86f78a6a021105ec?s=128

masaru-tech

October 26, 2017
Tweet

Transcript

  1. ॳΊͯͷRailsόʔδϣϯΞοϓ͕ ਏͯ͘ɺπϥͯ͘ɺͭΒ͔ͬͨ࿩ kawasaki.rb#053 @MasaruTech

  2. ࣗݾ঺հ • MasaruTechʢtwitter౳ʣ • େఉ কʢ͓͓͹ɹ·͞Δʣ • ීஈ͸RailsΛ࢖͓ͬͯ࢓ࣄ͍ͯ͠ΔSIer

  3. ॳΊͯ࢓ࣄͰ΍ͬͨRailsͷϝʔδϟʔ όʔδϣϯΞοϓ͕ਏ͔ͬͨΜͰɺ kawasaki.rbͰు࿐͍ͤͯͩ͘͞͞

  4. ໨࣍ • ਏ͔ͬͨᶃ • ਏ͔ͬͨᶄ • ਏ͔ͬͨᶅ • ൪֎ฤ

  5. ਏ͔ͬͨᶃ

  6. params͕ ActionController::Parameters ΦϒδΣΫτʹ

  7. strong parameterରԠΛ ͪΌΜͱ΍͍ͬͯͳ͍Օॴ͕ɺɺɺ XxxApi.search(params[:filters])Έ͍ͨʹࡶʹ΍͍ͬͯ ͨͱ͜Ζ͕ɺɺɺ େମ͸ͪΌΜͱstrong parameterରԠ͍ͯ͠Δ&ςετ Ͱ෼͔͕ͬͨɺAPIαʔόʔͱͷ࿈ܞՕॴ͸ελϒԽ͞ ΕͯΔͷͰ࣮ࡍʹಈ͔ͯ͠ݟΔ·Ͱؾ͔ͮͳ͍

  8. ਏ͔ͬͨᶄ

  9. Rails4.2→5.0΁্͛ͨ௚ޙ େྔʹग़Δ Deprecation Warning RDEPRECATION WARNING: Using positional arguments in

    functional tests has been deprecated,ɹin favor of keyword arguments, and will be removed in Rails 5.1.
  10. ςετίʔυͷॻ͖ํ͕มΘΔɻɻ get :show, { id: 1 }, nil, { notice:

    "This is a flash message" } ↓ keywordҾ਺Λར༻ͨ͠ελΠϧʹͳΔʂʂ get :show, params: { id: 1 }, flash: { notice: "This is a flash message" }, session: nil
  11. ͸ͼ͜Δࣗ༝ͳه๏ • get :index, {name: 'tom', age: 31} • get

    :index, name: 'tom', age: 31 • get ‘index’, {name: 'tom', age: 31} • get :index, test_params ͳͲͳͲ
  12. ֖Λ։͚ͯΈΕ͹ ࠓճͷRails5΁ͷόʔδϣϯΞοϓରԠͰɺ spec/controllersͷมߋ͸໿84%ʂʂ ͓ͦΒ͘ɺLint΍ίʔυϨϏϡʔ͕ͪΌΜͱͯ͠ ͍Δօ͞Μͷͱ͜ΖͰ͸ਏ͘ͳ͍Ͱ͠ΐ͏ʂ

  13. ਏ͔ͬͨᶅ

  14. x3

  15. RailsΞϓϦ͕3ͭ ࠓؔΘ͍ͬͯΔ΋ͷ͸ɺRailsΞϓϦ3ͭͰߏ੒͞ Ε͍ͯΔͷͰɺ͜ͷਏ͔ͬͨ࡞ۀΛ3ճ΍Γ·͠ ͨ

  16. ൪֎ฤ

  17. activerecord_session-storeͱ config/initializers/ new_framework_defaults.rb

  18. activerecord_session-storeΛ࢖͍ͬͯΔͱ config/initializers/new_framework_defaults.rbͰ Rails.application.config.active_record.belongs_t o_required_by_default=false Λࢦఆͯ͠΋্ॻ͖͞Εͳ͍ɺɺɺ

  19. ݪҼ http://y-yagi.tumblr.com/post/150899354290/rails ΑΓ Railsͷinitializers͸gemͷಡΈࠐΈޙʹ࣮ߦ͞Ε·͢ɻ ͦͷͨΊɺgem ͷதͰActiveRecordΛࢀর͍ͯ͠Δ(ActiveRecord::Baseʹରͯ͠module Λ௥Ճ͍ͯͨ͠Γ͢Δ)ɺ͔ͭɺద੾ͳܗͰActiveRecordΛࢀর͍ͯ͠ͳ ͍৔߹ɺActiveRecord::BaseͷॳظԽॲཧ͕ͦͷλΠϛϯάͰߦΘΕͯ ͠·͍ɺinitializersͰઃఆ͢Δલʹbelongs_to_required_by_defaultͷ஋ ͕ઃఆ͞Εͯ͠·͍·͢(belongs_to_required_by_defaultͷॳظ஋͸nil

    ͳͷͰɺ্هͷΑ͏ʹnil͕දࣔ͞ΕΔ)