Tag: Rails/アップグレード/4.2から5.0
関連ページ†
参考情報†
Rails 4.2からRails 5.0†
- GemfileのRailsバージョンをRails.5.0系の最新版に書き換えてbundle updateを実行。
bundle update
- 設定ファイルの更新。古い設定ファイルを上書きしようとしてくるので基本Yesで応える。後からgit diffで差分を見ながら移植したほうがよさげ。
bundle exec rails app:update
- IntelliJの場合Compare with Branchで比較する(Commitだと変更を戻したりできない)。routes.rbなど適宜commitしたバージョンを戻していく。
- app/models/application_record.rbを作成
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
- 各モデルクラスが継承するようにする(必須ではない)。
class Book < ApplicationRecord
end
移行後のWarningつぶし†
- デバッグ実行 or テストを実行してWarningをつぶしていく
MySQLの絵文字†
- MySQLで絵文字を使っている場合はar_innodb_row_format.rbの書き換えが必要。
before_filter is deprecated†
Rails Controller Testingのエラー†
- controllerのテストでassignを使っている場合以下のようなエラーが表示される
NoMethodError: assigns has been extracted to a gem. To continue using it,
add `gem 'rails-controller-testing'` to your Gemfile.
- Gemfileにrails-controller-testingを追加する
group :test do
gem "rails-controller-testing"
end
- .DEPRECATION WARNING: Using positional arguments in functional tests has been deprecated,
- 以下のようなエラー。
.DEPRECATION WARNING: Using positional arguments in functional tests has been deprecated,
in favor of keyword arguments, and will be removed in Rails 5.1.
Deprecated style:
get :show, { id: 1 }, nil, { notice: "This is a flash message" }
New keyword style:
get :show, params: { id: 1 }, flash: { notice: "This is a flash message" },
session: nil # Can safely be omitted.
- 指示通りにparamsやflashなどのキーワードを追加する。
post :create, params: {book: { author: @book.author, summary: @book.summary, title: @book.title } }
get :show, params: {id: @book}
Mime::JSON to: Mime::Type[:JSON]†
take_paramsの書き換え†
Protected Attributesの廃止†
XMLシリアライズ†
ActiveRecord::Base.raise_in_transactional_callbacks= is deprecated†
- environment.rbの以下の行で発生
require File.expand_path('../application', __FILE__)
- 実際はapplication.rbに含まれる以下の行を削除する。
config.active_record.raise_in_transactional_callbacks = true
Using a dynamic :action segment in a route is deprecated and will be removed in Rails 5.2.†
Minitestの実行後レポート表示時にエラー†
kind_of?(Hash)の変換†