VincentBlackdot

VincentBlackdot

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

Marked As Solved

Laetitia

Laetitia

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

Last Post!

VincentBlackdot

VincentBlackdot

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

Where Next?

Popular in Questions Top

Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

Other popular topics Top

hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31525 112
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement