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
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
3
690
CSC509 Lecture 12
javiergs
PRO
0
160
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
230
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
Macとオーディオ再生 2024/11/02
yusukeito
0
370
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.1k
役立つログに取り組もう
irof
28
9.6k
Jakarta EE meets AI
ivargrimstad
0
660
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
110
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
イベント駆動で成長して委員会
happymana
1
330
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
The Cult of Friendly URLs
andyhume
78
6k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Fireside Chat
paigeccino
34
3k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
[RailsConf 2023] Rails as a piece of cake
palkan
52
4.9k
Thoughts on Productivity
jonyablonski
67
4.3k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Music & Morning Musume
bryan
46
6.2k
Making Projects Easy
brettharned
115
5.9k
Typedesign – Prime Four
hannesfritz
40
2.4k
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ʹײँ :)
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠