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
Rails Tutorialを Phoenixで移植してみた
Search
hagiyat
August 25, 2015
Programming
3
2.2k
Rails Tutorialを Phoenixで移植してみた
* *
* + うそです
n ∧_∧ n
+ (ヨ(* ´∀`)E)
Y Y *
hagiyat
August 25, 2015
Tweet
Share
Other Decks in Programming
See All in Programming
テストケースの名前はどうつけるべきか?
orgachem
PRO
0
130
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
250
【re:Growth 2024】 Aurora DSQL をちゃんと話します!
maroon1st
0
770
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
2
460
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
180
17年周年のWebアプリケーションにTanStack Queryを導入する / Implementing TanStack Query in a 17th Anniversary Web Application
saitolume
0
250
バグを見つけた?それAppleに直してもらおう!
uetyo
0
180
数十万行のプロジェクトを Scala 2から3に完全移行した
xuwei_k
0
270
As an Engineers, let's build the CRM system via LINE Official Account 2.0
clonn
1
670
menu基盤チームによるGoogle Cloudの活用事例~Application Integration, Cloud Tasks編~
yoshifumi_ishikura
0
110
Haze - Real time background blurring
chrisbanes
1
510
선언형 UI에서의 상태관리
l2hyunwoo
0
140
Featured
See All Featured
Fireside Chat
paigeccino
34
3.1k
Faster Mobile Websites
deanohume
305
30k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.3k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
What's in a price? How to price your products and services
michaelherold
243
12k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
RailsConf 2023
tenderlove
29
940
Speed Design
sergeychernyshev
25
670
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
Transcript
Rails TutorialΛ PhoenixͰҠ২ͯ͠Έͨ @hagiyat 2015/08/25 #shibuya.ex#1
͡Ί·ͯ͠ɻഡ୩Ͱ͢ɻ github/twitter: hagiyat 2014/05͔Βגࣜձࣾnanapiʹॴଐ ձࣾͷTechBlogͪΐͬͱॻ͍ͯ·͢ http://blog.nanapi.co.jp/tech/author/hagiyat/ ͦΕ·ͰϑϦʔϥϯεΛ໊Γͳ͕Β৭ʑͳձࣾͰSIerͱͯ͠ಇ͍ͯ ͍ͨΓ͠·ͨ͠ 2014/12ͷݴޠೖΕ͔͑ࣄมͰॳΊͯRuby/Ruby on
Railsʹ͞ΘΔ Ҏ߱΄΅RubyͷΈॻ͍ͯա͍ͯ͝͠·͢
ͳͥElixirʹڵຯΛ࣋ͬͨͷ͔ʁ RubyΛॻ͍͍ͯͯҰ൪ָ͍͠ͷϝιουνΣΠϯ࡞Γ RubyΛॻ͖࢝Ίͯɺ͙͢ʹ@merborne͞Μͱ@yuroyoro͞ΜͷϒϩάͰ܆ ಃΛड͚ͨ ϝιουνΣΠϯʹ͔ܽͤͳ͍ͷߴ֊ؔ ߴ֊ؔͱ͍͑ؔܕݴޠ ؔܕݴޠࣗମʹڵຯ͕Θ͍͚ͨͲɺϝδϟʔͲ͜Ζͷݴޠ͙͢ʹֶͷ ͕࢝·Δͷ͕ਏ͔ͬͨ खͷ͖͖͍ͬͯͳ͍ؔܕݴޠΛٻΊΔ Elixirʂʁ
·ͣԿ͔ॻ͍ͯΈΑ͏ ۙͳڥΛ࠶ݱͯ͠ΈΔͱ͍͏ͷ͕ਅͬઌʹࢥ͍͍ͭͨ WAFɺ͍͙͢ʹPhoenixͱ͍͏ͷ͕ݟ͔ͭͬͨ ͦΕ͕Railsʹ͍ۙͱ͍͏ᷚฉ͖͚ͭͨ
ͬͯΈΑ͏ʂʂʢ҆ʣ
·ͣڥͮ͘Γ ηοτΞοϓʢ1ষʣͬ͘͞ͱࡁΜͩ ࣌࠷৽ͩͬͨPhoenix0.13.0ΛΠϯετʔϧ ࠓ͔Β͡ΊΔΜͩͬͨΒઈରanyenv - erlenv/exenv͕ Φεεϝ http://qiita.com/nownabe/items/ 67a27ddd23652676ffee
ͬͦ͘͞Phoenix.new EctoͷηοτΞοϓ ඪ४ͷσʔλετΞPostgreSQL PostgreSQLૉਓ͗ͯ͢ɺଓ͢Δ·ͰͪΐͬͱϋϚΔ ↑useraddతͳͱ͜Ζ localhost:4000ΛݟͯؾΛߴΊΔ ৽͞ϞνϕʔγϣϯʹͳΔ
֤GemͷସΛ୳͢ Rails Phoenix sqlite3 EctoͰαϙʔτ sass-rails brunch-config.jsͰઃఆ͢ΕOK uglifier brunch-config.jsͰઃఆ͢ΕOK coffee-rails
brunch-config.jsͰઃఆ͢ΕOKͷͣɻެࣜυΩϡϝϯ τʹTypescriptʹ͍ͭͯͷݴٴ͕͋Γ·͢ jquery-rails brunch-config.jsͰઃఆ͢ΕOK turbolinks ͳ͍ʂ jbuilder ViewͰରԠ sdoc ex_doc http://d.hatena.ne.jp/k-1/20130505/p1 rails_12factor ެࣜυΩϡϝϯτʹهࡌ͋Γ http://www.phoenixframework.org/docs/heroku
൪֎ฤɿϥΠϒϥϦ୳͠ͷ༑ http://getawesomeness.com/ ຊʹศར
Scaffoldతͳͭ mix phoenix.gen.html Ͱ࣮ߦͰ͖Δ http://www.phoenixframework.org/docs/mix-tasks ༻ײ΄΅ಉ͡ͱݴͬͯྑ͍ͱࢥ͍·͢ jsonϨεϙϯε༻ͷઐ༻λεΫ phoenix.gen.json ͕ଘࡏ ͢Δͷ͕ಛత
ActiveRecordతͳͭ Ectoͱ͍͏ඪ४ORM(?) PostgreSQL/MySQL/MSSQL/SQLite3͕͑Δ MongoDB͑ΔΑ͏ʹͳΔ༷ associationActiveRecordͱಉ͡ײ֮Ͱ͑Δ model͝ͱ࡞Δ(phoenix.gen.model)ͷɺmigrate୯ମ (ecto.gen.migration) mixλεΫͰ࣮ߦͰ͖Δ ͍͜͠ͱࢼ͍ͯ͠ͳ͍ͷͰɺ༻ײ·ͩอཹ
rails server/rails console RubyͰ͋ΕଈPryؔ࿈ͷGemΛ͋Ε͜ΕಥͬࠐΉ͚Ͳɺiex ૉͰઓ͑Δ iex -S mix phoenix.server ɺrails
server݉rails consoleͰɺ tmuxʹ͍͞͠ ิ͕ຊʹര byebugඪ४ͰೖͬͯΔ(ϒϨΠΫϙΠϯτషΔͷ؆୯ɻ͠ ͔ͯ͠εςοϓ࣮ߦͰ͖ͳ͍ʁ) show-docͰ͖Δ͚Ͳshow-sourceͰ͖ͳ͍ʁʁ
2ষऴྃɺ3ষ ൃੜ
Rails TutorialΛҠ২ͨ͠ͱݴ͕ͬͨɺΞϨӕͩ ࣮͍ͯ͘͠ʹͭΕͯɺ࣮ફʹೖͬͨΒViewपΓͰۤ͠Ή͜ ͱ͕༧Ͱ͖ͯ͠·ͬͨ Slim͕ͳ͍ʂ Turbolinks͕ͳ͍ʂ Cells͕ͳ͍ʂ Kaminari͕ͳ͍ʂ
ͬͱࠜຊతʹ RailsTutorialʹग़ͯ͜ͳ͍͚ͲɺElixir/Phoenixతʹ ॏཁͳ͜ͱ͕͍͔ͭ͘ ฒྻॲཧؔ࿈ Channelؔ࿈ ͜ΕΒͳ͍ͰͲ͏͢Μͷײ
PhoenixRailsͷҠ২(్த)ʹ͗͢ͳ͍ʁ ଟࢦ͍ͯ͠Δͱ͜Ζ͕ͪΐͬͱҧ͏ Channelͷଘࡏ 0.13.1Ҏ߱ɺWebSocketͱ͔PubSubͱ͔ Transport.LongPollͱ͔ɺίϯςϯπੜɾ৴ػೳ͔Β Εͨͱ͜ΖͷڧԽཱ͕ͬͨ͜ͱ͋Γɺ༨ܭͦ͏ײ͡ Δ
Elixirʹ͍ͭͯͷ·ͱΊ - πʔϧฤ iex͕࠷ߴ͗͢Δ REPLͳ͠ͰԿͰ͖ͳ͍ʹͱͬͯࢸߴͷπʔϧ mix૬͍͍͢ ૣͯ͘؆୯ mix.exsͷهड़ཧղ͍͢͠ ຊ֨తʹ͍ग़ͨ͠Βɺzshͷิࣗ࡞ͯ͠ͰͳΜͱ͔͠ ͍ͨ
Elixirʹ͍ͭͯͷ·ͱΊ - ݴޠฤ |> Ϡό͍ RubyͰϝιουνΣΠϯ͕ݏ͍ͩͬͨਓʹΦεεϝ͍ͨ͠ “hoge,fuga,piyo,baz” |> String.split(“,”) ͱ͍͏۩߹ʹɺॲ
ཧͷίϯςΩετ͕pipeͷޙʹ͋Δ(͜ͷྫͩͱString)ͬ ͯɺಡΈͯ͘͢Θ͔Γ͘͢ͳ͍Ͱ͔͢ʁ ฒྻॲཧ͕ຊʹΧδϡΞϧʹͰ͖Δ spawn_linkͱ͔؆୯͗͢ͰΘ͔Γ͗͢͢
Phoenixʹ͍ͭͯͷ·ͱΊ ίϯςϯπΛ৴͢ΔλΠϓͷαʔϏε։ൃ࣌ظঘૣ(͔ʁ) ࠓ·Ͱ͖ͬͯͨViewपΓͷศརͳಓ۩͕͑ͳ͍ͷ͕ਏ͍ ཧը໘ͱ͔ಛʹɺखؒΛ͔͚ͣʹαΫαΫը໘࡞ͬͨΓ͍ͨ͠ͷͰɺγϣʔτΧοτͷ උେࣄ͔ͳʔ RestfulͳAPI։ൃʁ ػೳతͳෆɺී௨ʹ͍ͬͯΔͰಛʹײ͡ͳ͍ ڧ͍ͯݴ͑KVSΛEcto͔Β͍͍ͨέʔε࣮֬ʹ͋ΔΑͳ͊ɾɾͱ͍͏ͱ͜Ζ Scala/Akkaൺֱͩͱ࣮ߦҰาৡΔ͚Ͳɺ࣮͕͘͠ͳͯ͘Ϗϧυ͕ૣ͍ Railsൺֱͩͱಉ࣌ଓ࣮ߦʹ༏Ґੑ͕͋Δ
্هཧ༝ʹΑΓɺདྷΔ͖Http2࣌ͷόοΫΤϯυͱͯ͠ຊʹͪΐ͏Ͳ͍͍ؾ͕͢Δ
Ε͍͚ͯͳ͍Ϣχοτςετ - extest ී௨ʹී௨ͷςετεΠʔτ͚ͩͲɺasyncઃఆ͕σϑΥ ϧτͰೖͬͯΔ RailsͰ͋Ε͜Εۤ࿑ͯ͠ฒྻςετͷΈΛߟ͑ͨΓ ͯͨ͠ͷͰɺΧδϡΞϧʹͰ͖͗ͯ͢ٽ͚Δ ͨͩɺ࣌ʑFactoryGirlFakerTimecopͳͲ͕࿀͘͠ͳ Δ͔͠Εͳ͍ ࣗಈ࣮ߦGuardͷ··Ͱ͍͍͔ͳʔ
ऴΘΓʹ Elixir/PhoenixɺϓϩμΫτͷೖ։࢝͠·ͨ͠ʂʂ ͦͷ͏ͪৄͤ͘͠Δ͔ɾɾ ͋ͱ͜ͷϓϩδΣΫτԠԉͯ͠·͢ https://github.com/awetzel/neovim-elixir neovimElixirઐ༻ͷIDEʹͳΔ͔ʂʁ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠