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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Router do | |
use Phoenix.Router, port: 4000 | |
use Plug.Static, mount: "/public" | |
use Plug.EncryptedSession, secret: "203802482048204820" | |
get "pages/:page", PagesController, :show, as: :page | |
get "files/*path", FilesController, :show | |
get "profiles/user-:id", UsersController, :show | |
resources "users", UsersController |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .iex.exs | |
defmodule IExHelpers do | |
def reload! do | |
Mix.Task.reenable "compile.elixir" | |
Mix.Task.run "compile.elixir" | |
end | |
end | |
iex = IExHelpers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gulpfile.js | |
# // Note the new way of requesting CoffeeScript since 1.7.x | |
# require('coffee-script/register'); | |
# // This bootstraps your Gulp's main file | |
# require('./Gulpfile.coffee'); | |
# assets | |
# ├── Gulpfile.coffee | |
# ├── Gulpfile.js |
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:
How to upgrade to Phoenix from 0.6.x
to 0.7.0
.
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |