Rails 5 deprecations and changes
- Ruby version
ruby '2.6.0' - The
:nothingoption for the render method is deprecated., please usehead: :okinstead
Deprecated
def index
render :nothing
end
Use
def index
head: :ok
end
The
*_filtermethods (before_filter, for example) are still supported, but deprecated and will be removed in Rails 5.1. Use*_actioninstead.A nice method redirect_back is being introduced in favor of redirect_to :back. It tries to redirect to an HTTP_REFERER or to the provided location, so you may use it inside your methods:
render :text is deprecated, as it does not render a text/plain response. Use render :plain instead or render :html to display a text/html page:
The respond_to and respond_with methods have been extracted to the responders gem, so be sure to include it in the Gemfile if you use those methods.
Rails 5 has introduced
models/application_record.rb
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
Use case:-
class User < ApplicationRecord
[...]
end
- Belongs to must have
optional: trueif its optional
belongs_to :some_parent, optional: true
- rails 5 has introduced migration version
Example use case:-
class CreateApps < ActiveRecord::Migration[4.2]
def change
create_table :apps do |t|
t.text :app_type
t.text :content
t.integer :user_id
t.boolean :saved
t.timestamps
end
end
end