I want to know why am I getting this error and how to fix. Could it be due to user id conflict in database? Another thing is this might not even be the file which is giving out this error.
defmodule MessengyrWeb.UserView do
use MessengyrWeb, :view
def render("show.json", %{user: user}) do
%{
user: user_json(user)
}
end
def user_json(user) do
hash_email = :crypto.hash(:md5, user.email) |> Base.encode16 |> String.downcase
avatar_url = "http://www.gravatar.com/avatar/#{hash_email}"
%{
id: user.id,
username: user.username,
avatarURL: avatar_url,
}
end
end
This is what I get after commenting out id: user.id
and user: user.username
and replacing hash_email
with a static integer.
def user_json(user) do
hash_email = 123
avatar_url = "http://www.gravatar.com/avatar/#{hash_email}"
%{
# id: user.id,
# username: user.username,
avatarURL: avatar_url,
}
end
user
variable has anil
instead of a user struct. We would have to see how you are retrieving the user to tell you why this is happening. But chances are you are callingAttendance.Repo.get
with an id that does not exist. – Justin Wood