Skip to content

Instantly share code, notes, and snippets.

@taylorbrooks
Last active June 5, 2016 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taylorbrooks/b9036c269632c39c903bad32f4b43145 to your computer and use it in GitHub Desktop.
Save taylorbrooks/b9036c269632c39c903bad32f4b43145 to your computer and use it in GitHub Desktop.
# grab a user
user = User |> preload(:emails) |> Repo.get_by!(api_key)
# set the current_user in conn.assigns
conn
|> assign(:current_user, user)
|> put_session(:user_id, user.id)
|> configure_session(renew: true)
# try to use in a view
<%= @current_user.emails %>
=> protocol Enumerable not implemented for #Ecto.Association.NotLoaded<association :emails is not loaded>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment