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
New Features in Rails 4.2
Search
murajun1978
February 21, 2015
Programming
0
890
New Features in Rails 4.2
murajun1978
February 21, 2015
Tweet
Share
More Decks by murajun1978
See All by murajun1978
Building Tebukuro with Hotwire and Rails
murajun1978
0
1.1k
Zeitwerk integration in Rails 6.0
murajun1978
0
100
Efficient development with GraphQL
murajun1978
0
280
Effective Debugging Apps in VS Code
murajun1978
1
860
tebukuro
murajun1978
0
110
Shinosaka.rb #17 Hands on
murajun1978
0
43
shinosakarb #11 Rails 4 Pattenrs
murajun1978
1
110
FactoryGirl LT
murajun1978
1
66
Shinosaka.rb #3
murajun1978
0
51
Other Decks in Programming
See All in Programming
みんなでプロポーザルを書いてみた
yuriko1211
0
260
EventSourcingの理想と現実
wenas
6
2.3k
RubyLSPのマルチバイト文字対応
notfounds
0
120
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.1k
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
220
最新TCAキャッチアップ
0si43
0
140
Remix on Hono on Cloudflare Workers
yusukebe
1
290
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
Realtime API 入門
riofujimon
0
150
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
Featured
See All Featured
Done Done
chrislema
181
16k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
For a Future-Friendly Web
brad_frost
175
9.4k
Adopting Sorbet at Scale
ufuk
73
9.1k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Faster Mobile Websites
deanohume
305
30k
Become a Pro
speakerdeck
PRO
25
5k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
Visualization
eitanlees
145
15k
Rails Girls Zürich Keynote
gr2m
94
13k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Transcript
New Features in Rails 4.2 ୈ65ճ Rubyؔ ษڧձ
about me ΉΒ͡ΎΜ murajun1978 Ruby <3 <3 <3
Shinosaka.rb #13 http://shinosakarb.doorkeeper.jp/events/19518 2 / 28
͢͜ͱ • Active Job • Global ID • Adequate Record
• Web Console • Foreign key support • Default Host for rails server
Active Job
Active Jobͱʁ queueing backends Active Job API Job adapter
Job࡞ $ rails generate job job_name
ಛఆͷΩϡʔͷJob࡞ $ rails generate job job_name —queue queue_name
JobΛΩϡʔʹొ
JobͷεέδϡʔϦϯά
ΞμϓλΛมߋ
ར༻Ͱ͖ΔΞμϓλ http://api.rubyonrails.org/classes/ActiveJob/ QueueAdapters.html
ίʔϧόοΫ • before_enqueue • around_enqueue • after_enqueue • before_perform •
around_perform • after_perform
Ωϡʔʹొ͞ΕΔ࣌ʹ࣮ߦ • before_enqueue • around_enqueue • after_enqueue
Job͕࣮ߦ͞ΕΔ࣌ʹ࣮ߦ • before_perform • around_perform • after_perform
ྫ֎ॲཧ
ඇಉظͰϝʔϧૹ৴
Global ID
URIʹΑΔϞσϧࢀর https://github.com/rails/globalid
Global IDͷੜ pry(main)> gid = post.to_gid => #<GlobalID:0x007f8ddfdb79e0 @uri=#<URI::GID gid://blog/Post/1>>
URI͕ੜ͞Εͨ ActiveRecordΦϒδΣΫτ
Global ID͔Β ModelͷใΛऔಘͯ͠ΈΔ gid.app #=> "blog" ɾΞϓϦέʔγϣϯ໊ ɾϞσϧ໊ gid.model_name #=>
"Post" ɾϞσϧΫϥε gid.model_class #=> Post(id: integer, title: string, published_at: datetime …) ɾID gid.model_id #=> "1"
Global ID͔ΒΦϒδΣΫτऔಘ globalid/lib/global_id/locator.rb GlobalID::Locator.locate gid => #<Post id: 1, title:
"Rubyؔ" ...>
Adequate Record
http://tenderlovemaking.com/2014/02/19/adequaterecord-pro- like-activerecord.html
ActiveRecord 2x faster ƅшƅ)ʂ
Rails 4.1 SELECT "posts".* FROM "posts" WHERE "posts"."id" = 1
LIMIT 1 SELECT "posts".* FROM "posts" WHERE "posts"."id" = 2 LIMIT 1 ݅ͷ͕มΘ͚ͬͨͩͳͷʹɺΫΤϦΩϟογϡ͞Εͯͳ͍
Rails 4.2 SELECT "posts".* FROM "posts" WHERE "posts"."id" = ?
LIMIT 1 [["id", 1]] SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1 [["id", 2]] Ωϟογϡ͞ΕͨΫΤϦʹΛ͍ͯ͠Δ
αϙʔτ͞Ε͍ͯΔͷ • find(id) • find_by(name: name) • find_by_name(name)
Ωϟογϡ͕ద༻͞Εͳ͍߹ • ϞσϧʹσϑΥϧτείʔϓ͕ઃఆ͞Ε͍ͯΔ • ϞσϧͰ୯Ұςʔϒϧܧঝ (STI) ͕༻͞Ε͍ͯΔ • PolymorphicΛͬͯΔ •
findͰ idͷྻΛ͢߹ • find(1,2) or find([1,2])
Web Console
ΤϥʔϖʔδͰσόοά
ಛఆͷϖʔδͰσόοά
ࢦఆIP͔ΒͷΈར༻͢Δ
Foreign Key Support
ϚΠάϨʔγϣϯͰ֎෦Ωʔ ͷՃɺআΛαϙʔτ
αϙʔτ͞ΕΔΞμϓλ • mysql • mysql2 • postgresql
Default Host for rails server
σϑΥϧτͷϗετ͕0.0.0.0͔Β localhost(127.0.0.1)ʹมߋ ֎෦PC͔ΒΞΫηε͢Δ߹ rails server -b 0.0.0.0
·ͱΊ • Active JobόοΫΤϯυͷΩϡʔγεςϜʹ͔͔ΘΒ ͣɺಉ͡هड़Ͱॻ͚Δ͕ྑ͍ • ܁Γฦ͢όονॲཧͳͲɺsidetipsidekiq-schedulerΛ ͏ͱྑ͍͔ • Global
IDActive JobҎ֎Ͱ͑ͦ͏ • Ruby on Rails 4.2 ϦϦʔεϊʔτಡ͏ • RailsͷContributorsʹײँ :)
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠