Skip to content

Commit

Permalink
add user changeset definition p.60 #55
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Jan 22, 2019
1 parent 4fd1cb8 commit 9883856
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions rumbl/lib/rumbl/accounts/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,12 @@ defmodule Rumbl.Accounts.User do

timestamps()
end

def changeset(user, attrs) do
user
|> cast(attrs, [:name, :username])
|> validate_required([:name, :username])
|> validate_length(:username, min: 1, max: 20)
end
end

7 changes: 7 additions & 0 deletions rumbl/lib/rumbl_web/controllers/user_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ defmodule RumblWeb.UserController do

alias Rumbl.Accounts

alias Rumbl.Accounts.User

def new(conn, _params) do
changeset = Accounts.change_user(%User{})
render(conn, "new.html", changeset: changeset)
end

def index(conn, _params) do
users = Accounts.list_users()
render(conn, "index.html", users: users)
Expand Down

0 comments on commit 9883856

Please sign in to comment.