Skip to content

Instantly share code, notes, and snippets.

@chrismccord
chrismccord / gist:4a62780056b08c60542d
Last active August 29, 2015 14:21
Phoenix Upgrade Instructions 0.13.0 to 0.13.1
@chrismccord
chrismccord / gist:0a3bf5229801d61f219b
Last active February 12, 2016 09:52
Phoenix Upgrade Instructions 0.12.x 0.13.0

Deps

First, clean your deps to avoid phoenix_html conflicts:

$ mix deps.clean phoenix --all

Next, bump phoenix:

{:phoenix, "~> 0.13"},

@chrismccord
chrismccord / gist:b3975ba356dba902ec88
Last active February 12, 2016 09:52
Phoenix Upgrade Instructions 0.11.x 0.12.0

Build-embedded and start permanent

Elixir v1.0.4 ships with two new important options for new projects. For projects generated prior to Elixir 1.0.4, add these options to your project entries in mix.exs:

build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod

Asset Digests (optional)

A new phoenix.digest task is now inluded which digests and compress static files and can be used during deploy. It also integrates with the static_path helper to render the proper asset paths from the manifest.

@chrismccord
chrismccord / gist:3603fd2735019f86c74b
Last active February 12, 2016 09:52
Phoenix 0.10 to 0.11.0 upgrade instructions

mix.exs

Add these functions to the bottom of mix.exs:

  # Specifies which paths to compile per environment
  defp elixirc_paths(:test), do: ["lib", "web", "test/support"]
  defp elixirc_paths(_),     do: ["lib", "web"]
@chrismccord
chrismccord / gist:cf51346c6636b5052885
Last active January 17, 2016 12:11
Phoenix 0.9 to 0.10.0 upgrade instructions

form_tag, link, CSRF changes

Plug 0.10.0 moves CSRF tokens from cookies back to sessions. To avoid future bumps on the road, a get_csrf_token/0 function has been added to controllers and imported into views. Update all your csrf token reference code to use the new function. Additionally, form_tag and link helpers have been added that will inject the csrf token for you automatically. You should transition to these new functions where possible, ie:

  <%= form_tag("/hello", method: :post) %>
    ... your form stuff. csrf is inject for you
  </form>
@chrismccord
chrismccord / gist:def6f4dc444b6a8f8d8b
Last active August 29, 2015 14:14
Phoenix Upgrade Instructions 0.8.x to 0.9.0

Endpoint

Plug.Static added an :only option which greatly improves performance by skipping disk reads at runtime. Replace your Plug.Static lines in endpoint.ex with the following configuration:

  plug Plug.Static,
    at: "/", from: :my_app,
    only: ~w(css images js favicon.ico robots.txt)

Router / Controller

@chrismccord
chrismccord / gist:9434b8fa208b3aae22b6
Last active August 29, 2015 14:13
Phoenix Upgrade Instructions 0.7.x to 0.8.0

Channel Changes

The channel layer received significant features and an overhaul of the topic abstraction. Upgrade your 0.7.x channels should only require a few simple steps.

Notable changes:

  • An updated version of phoenix.js is required, replace your priv/static/js/phoenix.js with https://github.com/phoenixframework/phoenix/blob/v0.8.0/priv/static/js/phoenix.js
  • "topic" is now just an identifier. You join topics, broadcast on topics, etc. Channels are are dispatched to based on topic patterns in the router.
  • Channel callbacks in 0.8.0 introduce the concept of outgoing events. Prior to 0.8.0, chanenls only processed incoming events via the event/3 callbacks. In 0.8.0, event/3 has been renamed to handle_in/3, and outgoing events callbacks can be defined via handle_out/3
  • All channel callbacks, such as join/3, leave/2, handle_in/3, and handle_out/3 now accept the socket as the last argument. This mimicks GenServer APIs
  • The return signature of handle_in, `handle_
var socket = new Phoenix.Socket(PewMiddle.config.socketPath);
PewMiddle.requestGame = function(username, callback) {
socket.join(PewMiddle.config.channel, "lobby", {username: username}, function(channel) {
var player = null;
channel.on("player:created", function(message) {
player = message;
});
channel.on("game:created", function(game) {
callback(game.id, player);
@chrismccord
chrismccord / gist:31340f08d62de1457454
Last active August 8, 2021 17:10
Phoenix Content Negotiation
# Controller option 1, implicit render selected based on format
defmodule MyApp.UserController do
use Phoenix.Controller
def show(conn, %{"id" => id}) do
render conn, :show, user: Repo.get(User, id)
end
end
# Controller option 2, explicit render with format pattern match
@chrismccord
chrismccord / gist:c24b2b516066d987f4fe
Last active April 24, 2016 23:17
Phoenix 0.6.x to 0.7.0 Upgrade Instructions

How to upgrade to Phoenix from 0.6.x to 0.7.0.

  1. 0.7.0 depends on Plug HEAD, so you'll need to include plug in your mix deps until the next plug release:
{:plug, github: "elixir-lang/plug", ref: "7040c89cb4cf1f1c6afdee379e5982a07d77a6c3"}
```

  1. The `Pheonix.Controller` functions html/2, json/2, text/2, redirect/2 and render/3 no longer halt automatically. *Important*: You must now explicity call `halt/1` yourself if you want to stop invoking further plugs after calling these functions. This is improtant for auth filtering plugs, ie:

```elixir