class StatsController
def update
# call sidekiq worker as normal
TwitterStatsWorker.perform_async(twitter_user.pin, twitter_user.token)
end
end
class TwitterStatsWorker
include Sidekiq::Worker
# .iex.exs | |
defmodule IExHelpers do | |
def reload! do | |
Mix.Task.reenable "compile.elixir" | |
Mix.Task.run "compile.elixir" | |
end | |
end | |
iex = IExHelpers |
defmodule MyApp.UserController do | |
use Phoenix.Controller | |
def show(conn, %{"id" => id}) do | |
render conn, "show", user: Repo.get!(user, id) | |
end | |
def index(conn, _) do | |
render conn, "index", users: Repo.all(User) | |
end |
setw -g mode-keys vi | |
set-option -g default-command "reattach-to-user-namespace -l zsh" | |
bind y run-shell "reattach-to-user-namespace -l zsh -c 'tmux show-buffer | pbcopy'" | |
unbind C-b | |
set -g prefix C-a | |
bind-key a send-prefix | |
# Add a binding to toggle status line | |
bind v set status |
defmodule Reduce do | |
def while(collection, initial, while_func, reduce_func) do | |
try do | |
Enum.reduce collection, initial, fn element, acc -> | |
if while_func.(element, acc) do | |
reduce_func.(element, acc) | |
else | |
throw {:halt, acc} | |
end |
If you're still on 0.4.x, follow [this 0.4x to 0.5.0 upgrade guide] (http://learnelixir.com/blog/2014/10/29/migrating-applications-from-phoenix-0-dot-4-1-to-phoenix-0-dot-5-0/), then head back over here.
Phoenix 0.6.0
brings some nice enhancements and a few backwards incompatible changes. The following steps should get your 0.5.x
apps up and running on the latest and greatest.
The Router no longer defines the default :browser
and :api
pipelines for you, but they remain the idiomatic defaults. You can copy the standard pipelines into your router:
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); |
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 yourpriv/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. In0.8.0
,event/3
has been renamed tohandle_in/3
, and outgoing events callbacks can be defined viahandle_out/3
- All channel callbacks, such as
join/3
,leave/2
,handle_in/3
, andhandle_out/3
now accept the socket as the last argument. This mimicks GenServer APIs - The return signature of
handle_in
, `handle_
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)
Update your web/static/vendor/phoenix.js
to the latest client: https://github.com/phoenixframework/phoenix/blob/v0.13.1/priv/static/phoenix.js
Simply create a test/support/channel_case.ex
file and replace the following MyApp
with your application:
defmodule MyApp.ChannelCase do
@moduledoc """
This module defines the test case to be used by