2.2.2+
2.3.1
ApplicationRecord
app/models/application_record.rb
with the following code:class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
before
callbacks would return false
in ActiveRecord and ActiveModel and thereby halting the entire execution chain.
throw(:abort)
config/application.rb: ActiveSupport.halt_callback_chains_on_return_false = false
ActiveJob
now inherits from ApplicationJob
app/jobs/application_job.rb
add the following codeclass ApplicationJob < ActiveJob::Base
end
assigns
and assert_template
in controller tests add gem 'rails-controller-testing'
to gemfileActionDispatch::Http::UploadFile
replace with Rack::Test::UploadedFile
Rails.application.config.enable_dependency_loading = true
ActiveModel::Serializers::Xml
has been extracted into a gem: gem 'activemodel-serializers-xml'
mysql
has been removed, use mysql2
rails
instead of rake
for running tasks and testsparams
will now return an object instead of a hash.
params.permit
then no changes are needed.params.permit([:proceed_to, :return_to]).to_h
protect_from_forgery
defaults to prepend: false
RAW
. Always specify the extension of your file to be parsed by an appropriate template handlercontent_tag_for
and div_for
have been removed in favor of just using content_tag
, to continue using the older view helper methods
add the gem gem 'record_tag_helper', '~> 1.0'
to gemfileprotected_attributes
gem is no longer supported in Rails 5!activerecord-deprecated_finders
gem is no longer supported in Rails 5!# config/environments/test.rb
Rails.application.configure do
config.active_support.test_order = :sorted
end
ActionController::Live
became a concern!
ActionController::Live
is included in another module that is included in your controller, then you should extend the module with ActiveSupport::Concern
belongs_to
will now trigger a validation error by default if there is no association present
optional: true
config.active_record.belongs_to_required_by_default = true
config.action_controller.per_form_csrf_tokens = true
Origin
header should be checked against
the site's origin: config.action_controller.forgery_protection_origin_check = true
mailers
, you can change it with this configuration: config.action_mailer.deliver_later_queue_name = :new_queue_name
config.action_mailer.perform_caching = true
config.active_record.dump_schemas = :all
config.ssl_options = { hsts: { subdomains: true } }
ActiveSupport.to_time_preserves_timezone = false
String
, but pass a Hash
instead, which will be converted to and from a JSON string automaticallyHashWithIndifferentAccess
class, move to using ActiveSupport::HashWithIndifferentAccess
config/secrets.yml
all keys are now loaded as symbols, using strings should be changed!app:update
sets it up in boot.rb, use it then add to gemfileboot.rb
Rails.application.config.action_dispatch.use_authenticated_cookie_encryption: false
gem 'rails', ~> '6.0'
for examplebundle update rails
rails app:update
new_framework_defaults.rb
file to uncomment any
modified settingsgem 'webpacker'
bin/rails webpacker:install
force_ssl
in controllers has been deprecated and will be removed in 6.1Rails.application.config.action_dispatch.use_cookies_with_metadata to false
actioncable → @rails/actioncable
activestorage → @rails/activestorage
rails-ujs → @rails/ujs
ActionCable.WebSocket = MyWebSocket
ActionCable.adapters.WebSocket = MyWebSocket
ActionCable.logger = myLogger
ActionCable.adapters.logger = myLogger
ActionCable.startDebugging()
ActionCable.logger.enabled = true
ActionCable.stopDebugging()
ActionCable.logger.enabled = false
.content_type
now returns the charset.media_type
to return just the mime typeconfig.hosts
setting# config/environments/development.rb
config.hosts << "example.com"
# can also use regexp:
config.hosts << /[a-zA-Z0-9].example.com/
zeitwerk
require_directive
statements are needed# config/application.rb
config.load_defaults 6.0
# if upgrdaing from older version of rails
# config/application.rb
config.autoloader :zeitwerk
app/models
app/models/concerns
app/models/concerns/foo.rb
can now be defined as Foo
and not
Concerns::Foo
app/api/base.rb
, usually
defined as Api::Base
will now be defined as just Base
ActiveSupport::Dependencies.autoload_paths.delete("#{Rails.root}/app/api")
config.cache_classes = false
to turn enable reloading in the test
envBootsnap
should be atleast version 1.4.2# config/application.rb
config.load_defaults 6.0
config.autoloader = :classic
* `has_many_attached` used to append new files to the collection
* new behavior: overwrites the current collection
* use `attach` to add new attachments without overwriting the existing ones