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
900
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
870
tebukuro
murajun1978
0
110
Shinosaka.rb #17 Hands on
murajun1978
0
43
shinosakarb #11 Rails 4 Pattenrs
murajun1978
1
120
FactoryGirl LT
murajun1978
1
66
Shinosaka.rb #3
murajun1978
0
51
Other Decks in Programming
See All in Programming
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
1
440
採用事例の少ないSvelteを選んだ理由と それを正解にするためにやっていること
oekazuma
2
1k
第5回日本眼科AI学会総会_AIコンテスト_3位解法
neilsaw
0
170
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
180
競技プログラミングへのお誘い@阪大BOOSTセミナー
kotamanegi
0
360
103 Early Hints
sugi_0000
1
230
今からはじめるAndroidアプリ開発 2024 / DevFest 2024
star_zero
0
1k
Criando Commits Incríveis no Git
marcelgsantos
2
170
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
460
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
710
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
250
nekko cloudにおけるProxmox VE利用事例
irumaru
3
420
Featured
See All Featured
Agile that works and the tools we love
rasmusluckow
328
21k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Adopting Sorbet at Scale
ufuk
73
9.1k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
Scaling GitHub
holman
458
140k
The Cost Of JavaScript in 2023
addyosmani
45
7k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Building Adaptive Systems
keathley
38
2.3k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Designing for Performance
lara
604
68k
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ʹײँ :)
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠