User controller:
def create(conn, %{"user" => user_params}) do
The problem with this is that user_params
is not decoded from JSON to map. So when it reaches the creation of the changeset:
changeset = User.changeset(%User{}, user_params)
This part will fail because user_params
is expected to be a map and not a string.
There are a few workarounds to this. The user_params
key can be removed and just pass the actual params. The signature would now look like this:
def create(conn, %{"name" => name, "email" => email}) do
Then you’ll have to create this:
user_params = %{"name" => name, "email" => email}) do
Or you can just do this:
def create(conn, user_params) do
Or you can use the original create
signature and just decode user_params
manually using Poison.
I thought it would be automatically decoded to a map. I’m trying to find out what is the idiomatic way of doing this.