Upgrade to Pro — share decks privately, control downloads, hide ads and more …

mini-rails_KaigiOnRails2026_EN.pdf

Avatar for nobo nobo
October 16, 2026
63

 mini-rails_KaigiOnRails2026_EN.pdf

Kaigi on Rails2026 の登壇資料です。
https://kaigionrails.org/2026/talks/Hitoshi-Noborikawa/

Avatar for nobo

nobo

October 16, 2026

Transcript

  1. Nobo I work at SonicGarden Inc. I organize Seto.rb. Also

    organizing 沖縄Ruby会議03 !(Feb 20 2027) @Hitoshi-Noborikawa 2
  2. The more I used Rails every day, the more I

    wondered what was happening inside. What is Rails.application.routes.draw? What does where actually do? When is a view loaded? I know — let's read the Rails source. 4
  3. I tried to look up the definition of where, but...

    So many methods I didn't understand: include, extend, included, define_method... Too early for me. Time to come back later. 5
  4. Expanding what I could read, bit by bit Metaprogramming Reading

    the source code of small gems Reading the code of projects I work on, closely Maybe I can do it now? 6
  5. Reading got easier, but Rails is still too big I

    understand the parts, but not the whole picture What if I build a small one to see the whole picture? 7
  6. About mini-rails A framework I built myself, modeled mainly on

    Rails 1–3. Strictly a learning project. I'll publish it on GitHub after this talk. 9
  7. What This Talk Covers Walking through Request → Response with

    a mini blog running on mini-rails. The focus is on the mini-rails implementation. 10
  8. Mapping to Rails mini-rails Rails MiniPack ActionPack MiniRecord ActiveRecord MiniView

    ActionView MiniModel ActiveModel MiniSupport ActiveSupport 13
  9. rackup → run MiniRails.application Rails: the Application sits on top

    of a middleware stack mini-rails: only the bare minimum middleware Reference: railties/lib/rails/application.rb 16
  10. Defines each action Kept simple on purpose. Rails is far

    more complex Reference: actionpack/lib/action_dispatch/routing/mapper.rb 20
  11. Finds the route, hands off to the controller GET /posts

    matches posts#index; dispatch hands off to the controller 22
  12. Post.order goes through all Rails: delegate(*QUERYING_METHODS, to: :all) No delegate

    here — order, where and find all go through define_method Reference: activerecord/lib/active_record/querying.rb 29
  13. all creates a new Relation If it were reused, A's

    conditions would leak into B Rails: all is current_scope || default_scoped — default_scope and scoping feed in mini-rails: just returns a new Relation 30
  14. Builds the SQL Rails: builds an Arel AST, and a

    Visitor turns it into SQL mini-rails: just concatenates strings 32
  15. save create_record is called for a new record valid? runs

    validations and run_callbacks runs before/after callbacks, but I'll skip those here 34
  16. Renders the view Rails splits this into Callbacks and ImplicitRender;

    mini-rails has only this method Reference: actionpack/lib/action_controller/metal/implicit_render.rb 37
  17. Reads the template, passes it to ERB Rails: caches templates

    mini-rails: reads them on every request Reference: actionview/lib/action_view/template.rb 39
  18. Response Rack → Router → Controller → View → Response

    Rails: returns it via Response#to_a mini-rails: named to_rack_response for clarity Reference: actionpack/lib/action_dispatch/http/response.rb 41
  19. Post works without any require Autoloaded at boot Rails: Zeitwerk

    also uses Ruby's autoload, and reloads on change mini-rails: same idea, once at boot — no reloading 44
  20. before_action Appended to an array when the class loads, then

    run per request via only / except Rails: AbstractController::Callbacks, which also controls conditions and execution order mini-rails: just runs an array of hashes 45
  21. Features I Couldn't Cover - MiniSupport::Concern - Migration - Validation

    - HashWithIndifferentAccess - MiniPack::Flash - MiniView::Helpers - MiniView::Partial 46
  22. What to Do After This Talk Read mini-rails Next read

    the Rails 1.x implementation https://github.com/Hitoshi-Noborikawa/mini-rails 47