Skip to content

Instantly share code, notes, and snippets.

@chrismccord
Last active February 12, 2016 09:52
Show Gist options
  • Save chrismccord/57805158f463d3369103 to your computer and use it in GitHub Desktop.
Save chrismccord/57805158f463d3369103 to your computer and use it in GitHub Desktop.
Phoenix Upgrade Instructions 0.13.x 0.14.0

First, bump your phoenix in mix.exs:

def deps do
  [{:phoenix, "~> 0.14"}, ...
end

phoenix_html

Update your phoenix_html version to 1.1.0 in mix.exs:

def deps do
  [{:phoenix, "~> 0.14"},
  {:phoenix_html, "~> 1.1"}, ...
end

then run $ mix deps.get

1.1 raises on missing assigns in your templates. If you had cases where you were using assigns that may or may not have been set, update your code as so:

0.13.x

<%= if @message do %>

0.14.0

<%= if assigns[:message] do %>

Controller

plug :action is now called automatically as the last plug in your controller. Simply remove it, ie:

0.13.x:

defmodule App.Controller do
  use App.Web, :controller
  
  plug :authenticate
  plug :action
  
  def show(conn, params) do
    ...
  end
end

0.14.0:

defmodule App.Controller do
  use App.Web, :controller
  
  plug :authenticate
  
  def show(conn, params) do
    ...
  end
end

View

The default template web/templates/layout/application.html.eex has been renamed to app.html.eex. Simply rename this file:

$ mv web/templates/layout/application.html.eex web/templates/layout/app.html.eex

Endpoint

The :format option in :render_errors has been renamed to :default_format. Update your config/*.exs accordingly.

Phoenix.PubSub.Redis

The Redis PubSub adapter has been extracted into its own project. If using redis, see the project's readme for installation and configuration instructions

Javascript client

Upgarde to the latest phoenix.js client by replacing web/static/vendor/phoenix.js with the latest version: https://raw.githubusercontent.com/phoenixframework/phoenix/6da5a66a11ff02e5629e3512649413afe9257bc7/priv/static/phoenix.js

Socket params can now be added to apply default, overridable params to all channel params, ie

let socket = new Phoenix.Socket("/ws", {params: {userToken: theToken}})

Logging has been enhanced. To enable logging, or add customized logging of events, add a callback to the socket options, ie:

let socket = new Phoenix.Socket("/ws", {
  logger: (kind, msg, data) => { console.log(${kind}: ${msg}, data) }
})
@orendon
Copy link

orendon commented Jun 30, 2015

Also worth to note resource deprecation in router:

resource "some_path", SomeController, only: [:edit, :update]

[warning] resource/4 in Phoenix router is deprecated, please use resources/3 with the singleton option instead.

Singleton option usage:
resources "some_path", SomeController, only: [:edit, :update], singleton: true

@yeongsheng-tan
Copy link

Sweet feedback @sevenseacat. I hit the same issue and your inputs helped.

@adamkittelson
Copy link

I upgraded to plug 0.13.0 as part of my phoenix 0.14.0 upgrade.

I needed to add plug Plug.RequestId to my Endpoint as a result. The phoenix new app generator puts it right above plug Plug.Logger so I followed suit.

@jcieslar
Copy link

@sevenseacat 👍 good job, thx.

@stevedomin
Copy link

There is also a new gzip option for Plug.Static, the new endpoint.ex generated by Phoenix looks like this:

# Serve at "/" the given assets from "priv/static" directory
#
# You should set gzip to true if you are running phoenix.digest
# when deploying your static files in production.
plug Plug.Static,
    at: "/", from: :ex_playground, gzip: false,
    only: ~w(css images js favicon.ico robots.txt)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment