Parameter mismatch on PUT

Hi, I am getting this error:

Phoenix.ActionClauseError at PUT /api/books/1
could not find a matching BookListWeb.BookController.update clause to process request. This typically happens when there is a parameter mismatch but may also happen when any of the other action arguments do not match. The request parameters are:
  %{"id" => "1", "subtitle" => "Yada"}

Here is the relevant route:

 $ mix phx.routes | grep PUT
warning: Plug.Conn.WrapperError.reraise/3 is deprecated. Use reraise/1 or reraise/4 instead.

           PUT     /api/users/:id           BookListWeb.UserController :update
           PUT     /api/books/:id           BookListWeb.BookController :update

And in book_controller.ex there is

def update(conn, %{"id" => id, "book" => book_params}) do

Finally, here is my schema:

defmodule BookList.BookSpace.Book do
  use Ecto.Schema
  import Ecto.Changeset

  schema "books" do
    field :author, :string
    field :notes, :string, default: "Just started."
    field :pages, :integer, default: 10
    field :pages_read, :integer, default: 0
    field :public, :boolean, default: false
    field :rating, :integer, default: 0
    field :title, :string
    field :subtitle, :string, default: ""
    field :user_id, :id


  @doc false
  def changeset(book, attrs) do
    |> cast(attrs, [:title, :subtitle, :author, :notes, :pages, :pages_read, :rating, :public])
    |> validate_required([:title, :author])

Oops, I think I see the problem … hold on a sec.

1 Like

Heh, yeah, your request parameters is missing a "book" entry that the function head that you showed requires. :slight_smile:

Yes, I am using Postman to test haven’t figured out how to do it. Something like

{“book”: {“subtitle”: “Yada”}}


That looks like it should match when it is supplied as the PUT body yeah.