Rails upgrade notes
mouse 2795 · person cloud · link
Last update
2024-12-05
2024
12-05
«rails notable/interesting changes from v4 to edge»



TODO


Rails 8

1
2
3
4
5
6
7
# importmap + dartsass, NO hotwire
rails new myapp-sass \
  --asset-pipeline=propshaft --css=sass \
  --skip-action-mailbox --skip-action-text \
  --skip-hotwire --skip-jbuilder --skip-test --skip-system-test \
  --skip-bootsnap --skip-brakeman --skip-ci --skip-dev-gems \
  --devcontainer
  • Rails.error.unexpected: report the given error when in production, or raise it when in development (for conditions not supposed to happen)
  • ActiveRecord: rollback a DB transaction with raise ActiveRecord::Rollback
  • ActiveRecord: stop callbacks chain (eg. validation) with throw :abort
  • YJIT enable by default (must be compiled in ruby)
  • Controller.rate_limit
  • .devcontainer folder when creating a new app.
  • default erb PWA files (manifest, service-worker) in app/views/pwa
  • GitHub CI files for Dependabot, Brakeman, RuboCop, and running tests by default (--skip-ci)
  • Brakeman by default for static analysis of security vulnerabilities (--skip-brakeman option)
  • ActiveRecord::Base.with_connection
  • allow_browser


New in rails (till 2019-07-06)

ActiveRecord

ActionView

ActiveJob / background jobs

ActionCable / websockets

Frontend

Email

ActiveStorage / upload to cloud -- guide

Security & Paranoia

Core/config changes

Development

  • rails console --sandbox don't write changes to DB -- PR+cfg
  • byebug > 8.2.1 is faster
  • faster dev reload: set in Gemfile group :development{gem 'listen', '~> 3.0.4'}

Tools / External gems

Testing

Info / Minor changes / Good to know


Upgrade experiences -- google search


References


Tools

  • scaling ruby apps
  • 📺 DHH youtube videos on writing sw well
  • MiniMagick
  • ruby's set: a collection of unordered values with no duplicates
  • obj.method(:method_name).source_location => mostra dov'e' definito il metodo
  • <<~TAG ... TAG al poso di <<-TAG...TAG rimuove gli spazi di indentazione!
  • thor -- build powerful command-line interfaces

Benchmark howto

docs, ips extension, article

1
2
3
4
5
6
7
8
9
require 'benchmark'

a = [:a, :b]
b = :b
n = 10000000
Benchmark.bm do |x|
  x.report { n.times do !(Array(a) & Array(b)).empty? end }
  x.report { n.times do Array(a).include?(b) end }
end
1
2
3
4
5
6
7
8
require 'benchmark/ips' # instructions per second
require 'uri'

uri = 'http://example.com/foos_json?foo=heyo'

Benchmark.ips do |x|
  x.report('URI.parse') { URI.parse(uri) }
end

vedi esempi di barnchmark in Hash#deep_merge PR


Books