This file contains 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
plug Plug.Static, | |
at: "/uploads", from: Path.expand('./uploads'), gzip: false |
This file contains 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
<!-- ... --> | |
<li> | |
<strong>Avatar:</strong> | |
<img src="<%= MyApp.Avatar.url({@user.avatar, @user}) %>"/> | |
</li> | |
<!-- ... --> |
This file contains 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
<!-- ... --> | |
<%= for user <- @users do %> | |
<tr> | |
<td><img src="<%= MyApp.Avatar.url({user.avatar, user}) %>"/></td> | |
<td><%= user.username %></td> | |
<td><%= user.email %></td> | |
<td class="text-right"> | |
<%= link "Show", to: user_path(@conn, :show, user), class: "btn btn-default btn-xs" %> | |
<%= link "Edit", to: user_path(@conn, :edit, user), class: "btn btn-default btn-xs" %> |
This file contains 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
user = Repo.get(User, 1) | |
# To receive a single rendition: | |
MyApp.Avatar.url({user.avatar, user}, :thumb) | |
#=> "https://bucket.s3.amazonaws.com/uploads/avatars/1/thumb.png?v=63601457477" | |
# To receive all renditions: | |
MyApp.Avatar.urls({user.avatar, user}) | |
#=> %{original: "https://.../original.png?v=1234", thumb: "https://.../thumb.png?v=1234"} |
This file contains 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
<%= form_for @changeset, @action, [multipart: true], fn f -> %> | |
<%= if @changeset.action do %> | |
<div class="alert alert-danger"> | |
<p>Oops, something went wrong! Please check the errors below.</p> | |
</div> | |
<% end %> | |
<div class="form-group"> | |
<%= label f, :avatar, class: "control-label" %> | |
<%= file_input f, :avatar, class: "form-control" %> |
This file contains 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
#... | |
def create(conn, %{"user" => user_params}) do | |
changeset = User.changeset(%User{}, user_params) | |
case Repo.insert(changeset) do | |
{:ok, _user} -> | |
conn | |
|> put_flash(:info, "User created successfully.") | |
|> redirect(to: user_path(conn, :index)) | |
{:error, changeset} -> |
This file contains 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.User do | |
use MyApp.Web, :model | |
use Arc.Ecto.Model | |
schema "users" do | |
field :avatar, MyApp.Avatar.Type | |
field :username, :string | |
field :email, :string | |
timestamps |
This file contains 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.Avatar do | |
use Arc.Definition | |
use Arc.Ecto.Definition | |
# ... | |
end |
This file contains 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
defp deps do | |
#... | |
{:arc_ecto, "~> 0.3.1"}, | |
{:arc, "0.2.0"}, | |
#... | |
end |
This file contains 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
scope "/", Roblist do | |
#... | |
resources "/users", UserController | |
#... | |
end |
NewerOlder