本日(12/17)、Phoenix 1.1が正式にリリースされましたので早速使ってみた。
1.1にはgettextを使った国際化対応のサポートや、channelのパフォーマンス改善、Instrumentation hooksの追加などがあるそうな。
前提
既に1.0で動いているPhoenixアプリケーションを1.1にアップデートすることが前提。
注意点
基本的にmix.exs
への変更が中心だが、1.1での後方互換の無い変更として、以下がアナウンスされているため、そこだけコードをいじる。
- Backward incompatible changes
- [View] The
@inner
assign has been removed in favor of explicit rendering with render/3and the new@view_module
and view_template assigns, for example:<%= @inner %>
is replaced by<%= render @view_module, @view_template, assigns %>
- [View] The
layoutなどで使っていた<%= @inner %>
を<%= render @view_module, @view_template, assigns %>
にしろ、とのこと。
手順
Phoenix本体のアップデート
$ mix archive.install https://github.com/phoenixframework/phoenix/releases/download/v1.1.0/phoenix_new-1.1.0.ez
依存関係のアップデート
mix.exs
を以下のように変更する。
mix.exs
# ...省略
# Configuration for the OTP application.
#
# Type `mix help compile.app` for more information.
def application do
[mod: {Test, []},
applications: [:phoenix, :phoenix_html, :cowboy, :logger, :gettext, # gettextを追加
:phoenix_ecto, :postgrex]]
end
# ...省略
# Specifies your project dependencies.
#
# Type `mix help deps` for examples and options.
defp deps do
[{:phoenix, "~> 1.1.0"}, # phoenixのバージョンを1.1に
{:phoenix_ecto, "~> 2.0"}, # phoenixのバージョンを2.0に
{:postgrex, ">= 0.0.0"},
{:phoenix_html, "~> 2.3"}, # phoenixのバージョンを2.3に
{:phoenix_live_reload, "~> 1.0", only: :dev},
{:gettext, "~> 0.9"}, # gettextを追加
{:cowboy, "~> 1.0"}]
end
# ...省略
編集後、mix deps.update --all
で依存関係を更新。
後方互換のない変更への対応
layoutなどで使っていた<%= @inner %>
を<%= render @view_module, @view_template, assigns %>
にしろ、とのことなので、まずはgrepするなりして@innner
を使っているところを洗い出す。あとは単純に置き換えればOK。
動作確認
$ mix test
テストしてmix phoenix.server
して普通にアクセスできれば問題ないかと。