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

[RailsConf 2023 Opening Keynote] The Magic of R...

[RailsConf 2023 Opening 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

April 24, 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. • Railties are the core of the framework • Railties

    control load order and when hooks should be run
  5. • 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
  6. 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
  7. # 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
  8. • 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
  9. • 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
  10. # 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
  11. # 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
  12. # 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
  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_writers(mixin, name)

    mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1 def #{name}=(value) association(:#{name}).writer(value) end CODE end end end
  15. # 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
  16. • Powerful tool that enables us to build beautiful, simple

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

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

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

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

    conference 1st contribution 2015 First RailsConf 2017 Join Rails Core 2023 This RailsConf