Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
kawasakirb053
Search
masaru-tech
October 26, 2017
0
5.5k
kawasakirb053
辛かった愚痴スライドです
masaru-tech
October 26, 2017
Tweet
Share
More Decks by masaru-tech
See All by masaru-tech
Sidekiqでクラスターモードは使えるのか? / kawasakirb_060
masarutech
0
810
stimulusの感触
masarutech
0
47
kawasakirb051
masarutech
0
510
「はやい、やすい、うまい?」React Native
masarutech
1
610
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.5k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
700
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
44
2.4k
Code Review Best Practice
trishagee
68
18k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
17
940
VelocityConf: Rendering Performance Case Studies
addyosmani
330
24k
Navigating Team Friction
lara
187
15k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.8k
Transcript
ॳΊͯͷRailsόʔδϣϯΞοϓ͕ ਏͯ͘ɺπϥͯ͘ɺͭΒ͔ͬͨ kawasaki.rb#053 @MasaruTech
ࣗݾհ • MasaruTechʢtwitterʣ • େఉ কʢ͓͓ɹ·͞Δʣ • ීஈRailsΛ͓ͬͯࣄ͍ͯ͠ΔSIer
ॳΊͯࣄͰͬͨRailsͷϝʔδϟʔ όʔδϣϯΞοϓ͕ਏ͔ͬͨΜͰɺ kawasaki.rbͰు࿐͍ͤͯͩ͘͞͞
࣍ • ਏ͔ͬͨᶃ • ਏ͔ͬͨᶄ • ਏ͔ͬͨᶅ • ൪֎ฤ
ਏ͔ͬͨᶃ
params͕ ActionController::Parameters ΦϒδΣΫτʹ
strong parameterରԠΛ ͪΌΜͱ͍ͬͯͳ͍Օॴ͕ɺɺɺ XxxApi.search(params[:filters])Έ͍ͨʹࡶʹ͍ͬͯ ͨͱ͜Ζ͕ɺɺɺ େମͪΌΜͱstrong parameterରԠ͍ͯ͠Δ&ςετ Ͱ͔͕ͬͨɺAPIαʔόʔͱͷ࿈ܞՕॴελϒԽ͞ ΕͯΔͷͰ࣮ࡍʹಈ͔ͯ͠ݟΔ·Ͱؾ͔ͮͳ͍
ਏ͔ͬͨᶄ
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.
ςετίʔυͷॻ͖ํ͕มΘΔɻɻ 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
ͼ͜Δࣗ༝ͳه๏ • get :index, {name: 'tom', age: 31} • get
:index, name: 'tom', age: 31 • get ‘index’, {name: 'tom', age: 31} • get :index, test_params ͳͲͳͲ
֖Λ։͚ͯΈΕ ࠓճͷRails5ͷόʔδϣϯΞοϓରԠͰɺ spec/controllersͷมߋ84%ʂʂ ͓ͦΒ͘ɺLintίʔυϨϏϡʔ͕ͪΌΜͱͯ͠ ͍Δօ͞Μͷͱ͜ΖͰਏ͘ͳ͍Ͱ͠ΐ͏ʂ
ਏ͔ͬͨᶅ
x3
RailsΞϓϦ͕3ͭ ࠓؔΘ͍ͬͯΔͷɺRailsΞϓϦ3ͭͰߏ͞ Ε͍ͯΔͷͰɺ͜ͷਏ͔ͬͨ࡞ۀΛ3ճΓ·͠ ͨ
൪֎ฤ
activerecord_session-storeͱ config/initializers/ new_framework_defaults.rb
activerecord_session-storeΛ͍ͬͯΔͱ config/initializers/new_framework_defaults.rbͰ Rails.application.config.active_record.belongs_t o_required_by_default=false Λࢦఆ্ͯ͠ॻ͖͞Εͳ͍ɺɺɺ
ݪҼ http://y-yagi.tumblr.com/post/150899354290/rails ΑΓ RailsͷinitializersgemͷಡΈࠐΈޙʹ࣮ߦ͞Ε·͢ɻ ͦͷͨΊɺgem ͷதͰActiveRecordΛࢀর͍ͯ͠Δ(ActiveRecord::Baseʹରͯ͠module ΛՃ͍ͯͨ͠Γ͢Δ)ɺ͔ͭɺదͳܗͰActiveRecordΛࢀর͍ͯ͠ͳ ͍߹ɺActiveRecord::BaseͷॳظԽॲཧ͕ͦͷλΠϛϯάͰߦΘΕͯ ͠·͍ɺinitializersͰઃఆ͢Δલʹbelongs_to_required_by_defaultͷ ͕ઃఆ͞Εͯ͠·͍·͢(belongs_to_required_by_defaultͷॳظnil
ͳͷͰɺ্هͷΑ͏ʹnil͕දࣔ͞ΕΔ)