Skip to content

Instantly share code, notes, and snippets.

@claudiug
Forked from yahonda/ruby31onrails.md
Created December 26, 2021 10:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save claudiug/bdc2fb70b10d19513208c816588aed92 to your computer and use it in GitHub Desktop.
Save claudiug/bdc2fb70b10d19513208c816588aed92 to your computer and use it in GitHub Desktop.
Ruby 3.1 on Rails

Ruby 3.1 on Rails

Actions required to use Ruby 3.1.0 with Rails

Rails 7.0.Z

  • Rails 7.0.0 is not compatible with Ruby 3.1.0.

  • "Rails::Engine is abstract, you cannot instantiate it directly.."

    $ bin/rails s
    Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead.
    [WARNING] Could not load command "rails/commands/server/server_command". Error: Rails::Engine is abstract, you cannot instantiate it directly..
    /path/to/rails/railties/lib/rails/railtie.rb:246:in `initialize'
    /path/to/rails/railties/lib/rails/railtie.rb:184:in `new'
    /path/to/rails/railties/lib/rails/railtie.rb:184:in `instance'
    /path/to/rails/railties/lib/rails/railtie.rb:223:in `method_missing'
    /path/to/rails/activesupport/lib/active_support/descendants_tracker.rb:90:in `descendants'
  • Use 7-0-stable branch until Rails 7.0.1 is released.

    gem "rails", github: "rails/rails", branch: "7-0-stable"

Rails 6.1.Z

  • Use Rails 6.1.4 to support database.yml with aliases.
  • If you use secrets.yml with aliases, use 6-1-stable branch.
    gem "rails", github: "rails/rails", branch: "6-1-stable"

Rails 6.0.Z

  • You will likely get this error.
    Psych::BadAlias: Unknown alias: default
  • Upgrade to Rails 6.1.4 or higher.
  • No Psych 4 support has been backported to Rails 6.0. Use Psych 3 as a workaround.
    gem "psych", "~> 3.0"

Details - if you are interested

Maintenance Policy for Ruby on Rails

https://guides.rubyonrails.org/maintenance_policy.html As of Dec 25, 2021, Supporting Ruby 3.1 with Rails should not be security issues.

  • Rails 7.0.Z accepts bug fixes.
  • Rails 6.1.Z accepts security issues only.
  • Rails 6.0.Z accepts severe security issues only.

Changes to support Ruby 3.1

  • Add Class#descendants
  • Psych 4 support
  • net-smtp, net-imap, net-pop are bundled gems
  • Ruby 3.1 performance optimization
  • DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated.

Add Class#descendants


Psych 4 support


YAML files used in Rails

  • config/database.yml
    default: &default
      adapter: sqlite3
      pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
      timeout: 5000
    
    development:
      <<: *default
      database: db/development.sqlite3
    
    # Warning: The database defined as "test" will be erased and
    # re-generated from your development database when you run "rake".
    # Do not set this db to the same as development or production.
    test:
      <<: *default
      database: db/test.sqlite3
    
    production:
      <<: *default
      database: db/production.sqlite3
  • config/secrets.yml (Rails 4.1+) or config/secrets.yml.enc (Rails 5.1+)
    • You will get this error run Rails 6.1 with Ruby 3.1.0
    $ bin/rails s
    => Booting Puma
    => Rails 6.1.4.4 application starting in development
    => Run `bin/rails server --help` for more startup options
    Exiting
    /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:430:in `visit_Psych_Nodes_Alias': Unknown alias: default (Psych::BadAlias)
  • config/credentials.yml.enc
    • No alias supported in Rails main branch because it should not need alias support.

net-smtp, net-imap, net-pop are bundled gems

  • If you need to use mail gem, add them explicitly in your Gemfile
  • mikel/mail#1439

Ruby 3.1 performance optimization


did_you_mean gem shows this deprecation at thor

  • Calling DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call DidYouMean.correct_error(error_name, spell_checker)' instead.
  • rails/thor#761

Enjoy Ruby 3.1!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment