No function clause matching in SmartcomClientWeb.TemplateController.create/2

hi i am using ajax to post data to my db, but keep running into this error.

no function clause matching in SmartcomClientWeb.TemplateController.create/2

this is my is my ajax code

$("#push_data").click(function() {
    params = $("form.form-temp").serialize();
    $.ajax({
        type: 'POST',
        url: '/create/template',
        data: params,
        success: function (response) {
            console.log(response)
        },
        error: function (error) {
           console.log(error)
        }
    })
})

then this is my function

def create(conn, %{“template” => template_params}) do
case Templates.create_template(template_params) do
{:ok, template} ->
conn
|> put_flash(:info, “Template created successfully.”)
|> redirect(to: Routes.template_path(conn, :show, template))

  {:error, %Ecto.Changeset{} = changeset} ->
    render(conn, "new.html", changeset: changeset)
end

end

Try to add something like this… to check what You receive.

def create(conn, %{“template” => template_params} = params) do
  IO.inspect(params, label: "PARAMS")
end

BTW You misplaced fence in your post. It should be around your code…

Do you really send a map with a key template? Maybe you just send the template_params rawly.
kokolegorille is right, IO.inspect is a good idea here.

But i notice that the inspect won’t never be executed. It will fail immediately for the same reason.
Try this:

def create(conn, params) do
  IO.inspect(params, label: "PARAMS")
end
2 Likes

it is still generating the same error.

Sorry, I meant something else… put it above the other, and check the params You receive.

def create(conn, params) do
  IO.inspect(params, label: "PARAMS")
end

as mentionned by @Laetitia

@kokolegorille and @Laetitia
Thank you my issues has been revolved