Skip to content

Commit

Permalink
add create_user function p.65 #55
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Jan 23, 2019
1 parent 37f4080 commit 227afab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions rumbl/lib/rumbl/accounts/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ defmodule Rumbl.Accounts do
User.changeset(user, %{})
end

def create_user(attrs \\ %{}) do
%User{}
|> User.changeset(attrs)
|> Repo.insert()
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 @@ -19,4 +19,11 @@ defmodule RumblWeb.UserController do
user = Accounts.get_user(id)
render(conn, "show.html", user: user)
end

def create(conn, %{"user" => user_params}) do
{:ok, user} = Accounts.create_user(user_params)
conn
|> put_flash(:info, "#{user.name} created!")
|> redirect(to: Routes.user_path(conn, :index))
end
end

0 comments on commit 227afab

Please sign in to comment.