Skip to content

Instantly share code, notes, and snippets.

@Hajto
Created December 3, 2015 13:16
Show Gist options
  • Save Hajto/4a96c8b985f8341e7011 to your computer and use it in GitHub Desktop.
Save Hajto/4a96c8b985f8341e7011 to your computer and use it in GitHub Desktop.
def edit(conn, %{ "edit" => newData }) do
#TODO: naprawic to
case Repo.one(User.unique_user(User, "login")) do
nil -> conn
|> put_flash(:error, "Błąd bazy danych")
result ->
if Map.get(newData, "password") == "" do
newData = Map.put(newData,"password", result.password)
end
if Map.get(newData, "avatar") == "" do
newData = Map.put(newData,"avatar", result.avatar)
end
changeset = User.changeset(result, newData)
case Repo.update(changeset) do
{:ok, changeset} -> conn
|> put_flash(:info, "dziala")
|> redirect to: "/"
{:error, error} ->
conn
|> put_flash(:error, "nie pyklo")
|> redirect to: "/"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment