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
-- おまけ用のメモ | |
> body = Http.jsonBody (UserEncoder.user User.new) | |
StringBody "application/json" "{\"id\":0,\"name\":\"\",\"email\":\"\"}" | |
: Http.Body | |
> import Model.UserDecoder as UserDecoder | |
> Http.post "http://localhost:4000/exmamples" body UserDecoder.user | |
Request { method = "POST", headers = [], url = "http://localhost:4000/exmamples", body = StringBody "application/json" "{\"id\":0,\"name\":\"\",\"email\":\"\"}", expect = { responseType = "text", responseToResult = <function> }, timeout = Nothing, withCredentials = False } | |
: Http.Request Model.User.Schema |
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 MacroExample do | |
alias User | |
alias Post | |
defmacro get_struct_info( | |
{:%, _, [{_, _, struct_name}, {:%{}, _, values}]}) do | |
quote do | |
{unquote(struct_name), unquote(values)} | |
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
defmodule SampleApp.User do | |
use SampleApp.Web, :model | |
alias SampleApp.Helpers.Encryption | |
schema "users" do | |
field :name, :string | |
field :email, :string | |
field :password, :string, virtual: true | |
field :password_digest, :string |
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
<%= form_for @changeset, @action, fn f -> %> | |
<%= if f.errors != [] do %> | |
<div class="alert alert-danger"> | |
<p>Oops, something went wrong! Please check the errors below:</p> | |
<ul> | |
<%= for {attr, message} <- f.errors do %> | |
<li><%= humanize(attr) %> <%= message %></li> | |
<% end %> | |
</ul> | |
</div> |
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
<h2>Show user</h2> | |
<ul> | |
<li> | |
<strong>Name:</strong> | |
<%= @user.name %> | |
</li> | |
<li> |
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
<h2>Listing users</h2> | |
<table class="table"> | |
<thead> | |
<tr> | |
<th>Name</th> | |
<th>Email</th> | |
<th>Password</th> | |
<th></th> |
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 EctoModelsSample.User do | |
use EctoModelsSample.Web, :model | |
use Ecto.Model.Callbacks | |
before_insert :set_password_digest | |
schema "users" do | |
field :name, :string | |
field :email, :string | |
field :password_digest, :string |
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 SafetyboxSample do | |
def encrypt(password) do | |
Safetybox.encrypt(password) | |
end | |
def authentication(_userid, _user_name, password) do | |
encrypt_password = "" # DBからユーザデータを取得する処理が入る | |
Safetybox.is_decrypted(password, encrypt_password) | |
end | |
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
defp deps do | |
[ { :safetybox, "~> 0.1" } ] | |
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
defmodule TrotSample.Router do | |
use Trot.Router | |
use Trot.Template | |
get "/", do: 200 | |
get "/hello" do | |
"Hello Trot!!" | |
end |
NewerOlder