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

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
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

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 131117 1222
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36820 110
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
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