Hi again!
I’ve got user authentication set up using openmaize, I’d like to automatically fill a Post field with the @current_user USERNAME when the form is submitted (each post will belong to a user) without a form field that the user has to fill in.
In rails, I can do something like this :
@post.user = current_user.id
And it will works.
Here’s the action of my post controller :
def create(conn, %{"post" => post_params}) do
current_user = conn.assigns.current_user
changeset = Post.changeset(%Post{}, note_params)
case Repo.insert(changeset) do
{:ok, _post} ->
conn
|> put_flash(:info, "Post created successfully.")
|> redirect(to: post_path(conn, :index))
{:error, changeset} ->
render(conn, "new.html", changeset: changeset)
end
end
I’m using current_user = conn.assigns.current_user
but it doesnt work.
Thanks in advance
Cheers!