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

[Rails World 2023 - Day 1 Closing Keynote] - Th...

[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails

Today we're going to explore the magic of Rails. We'll look at the philosophy behind the framework as well as the overall structure of the components. We'll explore some of the common patterns that Rails uses to build agnostic and beautiful interfaces, and the techniques it implements to hide complexity so you can focus building your application. By the end of this talk you'll feel more confident navigating the Rails codebase and better understand the patterns it uses to create the framework we all know and love. But Rails is so much more than its design and architecture. We'll dive into my motivations for working on the framework and why the community is so important to the long term success of Rails.

Eileen M. Uchitelle

October 05, 2023
Tweet

More Decks by Eileen M. Uchitelle

Other Decks in Programming

Transcript

  1. RUBY ON RAILS Active Record Active Support Active Model Active

    Job Active Storage Action Mailer Action Pack Action View Action Cable Action Text Action Mailbox Railties
  2. USER FACING Active Record Active Support Active Model Active Job

    Active Storage BACKEND NAMING CONVENTION Action Mailer Action Pack Action View Action Cable Action Text Action Mailbox USER FACING
  3. Active Record Active Support Active Model Active Job Active Storage

    Action Mailer Action Pack Action View Action Cable Action Text Action Mailbox BACKEND USER FACING Railties GLUE NAMING CONVENTION
  4. # activerecord/lib/active_record/railtie.rb initializer "active_record.log_runtime" do require "active_record/railties/controller_runtime" ActiveSupport.on_load(:action_controller) do include

    ActiveRecord::Railties::ControllerRuntime end require "active_record/railties/job_runtime" ActiveSupport.on_load(:active_job) do include ActiveRecord::Railties::JobRuntime end end
  5. # activerecord/lib/active_record/railtie.rb initializer "active_record.log_runtime" do require "active_record/railties/controller_runtime" ActiveSupport.on_load(:action_controller) do include

    ActiveRecord::Railties::ControllerRuntime end require "active_record/railties/job_runtime" ActiveSupport.on_load(:active_job) do include ActiveRecord::Railties::JobRuntime end end
  6. # activerecord/lib/active_record/railtie.rb initializer "active_record.log_runtime" do require "active_record/railties/controller_runtime" ActiveSupport.on_load(:action_controller) do include

    ActiveRecord::Railties::ControllerRuntime end require "active_record/railties/job_runtime" ActiveSupport.on_load(:active_job) do include ActiveRecord::Railties::JobRuntime end end
  7. • Railties are the core of the framework • Railties

    control load order and when hooks should be run
  8. • Railties are the core of the framework • Railties

    control load order and when hooks should be run • Enables components to work together without adding dependencies
  9. module ActiveRecord module ConnectionAdapters class AbstractAdapter # define interface end

    end end module ActiveRecord module ConnectionAdapters class PostgresqlAdapter < AbstractAdapter # inherit or redefine interface end end end
  10. # activestorage/lib/active_storage/service/gcs_service.rb class ActiveStorage class Service::GCSService < Service def delete(key)

    instrument :delete, key: key do file_for(key).delete rescue Google::Cloud::NotFoundError # Ignore files already deleted end end end end
  11. • Consistent interface for all supported libraries • Simpli fi

    es Rails code to avoid using `is_a?` • Makes it easy for apps to swap out adapters / services
  12. • Consistent interface for all supported libraries • Simpli fi

    es Rails code to avoid using `is_a?` • Makes it easy for apps to swap out adapters / services • Lowers the maintenance burden
  13. # activerecord/lib/active_record/associations/builder/ association.rb class ActiveRecord::Associations::Builder class Association def self.define_readers(mixin, name)

    mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1 def #{name} association(:#{name}).reader end CODE end end end
  14. # activerecord/lib/active_record/associations/builder/ association.rb class ActiveRecord::Associations::Builder class Association def self.define_readers(mixin, name)

    mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1 def #{name} association(:#{name}).reader end CODE end end end
  15. # activerecord/lib/active_record/associations/builder/ association.rb class ActiveRecord::Associations::Builder class Association def self.define_readers(mixin, name)

    mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1 def #{name} association(:#{name}).reader end CODE end end end
  16. # activerecord/lib/active_record/associations/builder/ association.rb class ActiveRecord::Associations::Builder class Association def self.define_readers(mixin, name)

    mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1 def #{name} association(:#{name}).reader end CODE end end end
  17. # activerecord/lib/active_record/associations/builder/ association.rb class ActiveRecord::Associations::Builder class Association def self.define_writers(mixin, name)

    mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1 def #{name}=(value) association(:#{name}).writer(value) end CODE end end end
  18. # activerecord/lib/active_record/associations/builder/ association.rb class ActiveRecord::Associations::Builder class Association def self.define_writers(mixin, name)

    mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1 def #{name}=(value) association(:#{name}).writer(value) end CODE end end end
  19. • Powerful tool that enables us to build beautiful, simple

    APIs • Hides complexity from your application
  20. • Powerful tool that enables us to build beautiful, simple

    APIs • Hides complexity from your application • Where "Rails Magic" comes from
  21. 2010 Introduced to Rails 2011 Big Nerd Ranch 2014 1st

    conference 1st contribution 2015 First RailsConf
  22. 2010 Introduced to Rails 2011 Big Nerd Ranch 2014 1st

    conference 1st contribution 2015 First RailsConf 2017 Join Rails Core
  23. 2010 Introduced to Rails 2011 Big Nerd Ranch 2014 1st

    conference 1st contribution 2015 First RailsConf 2017 Join Rails Core 2023 Rails is 20!