No function clause matching in Ecto.Changeset.cast

Hey all! New to Elixir - I’m trying to edit an entry in postgresql, and I can’t see what I’m doing wrong - I keep getting this error when I try to access the URL. Want to be seeing a page with the entry passed in by its “id” in the path. see below:

router.ex:

 scope "/", Discuss do
    pipe_through :browser 

    get "/", TopicController, :index
    get "/topics/new", TopicController, :new
    post "/topics", TopicController, :create
    get "/topics/:id/edit", TopicController, :edit
    put "/topics/:id", TopicController, :update
  end

controller:

  def edit(conn, %{"id" => topic_id}) do
    topic = Repo.get(Topic, topic_id)
    changeset = Topic.changeset(topic)

    render conn, "edit.html", changeset: changeset, topic: topic
  end

model:

defmodule Discuss.Topic do
  use Discuss.Web, :model

  schema "topics" do
    field :title, :string
  end

  def changeset(struct, params \\ %{}) do
    struct
    |> cast(params, [:title])
    |> validate_required([:title])
  end

I think I may have done something wrong in the controller edit function, but for the life of me I can’t figure out what. Any help appreciated. Thanks!

In any case, if someone could make the error here a little less ambiguous, I’m sure that would help to. Thanks!

Your Repo.get call in the controller seems to have returned nil meaning, that there was no item with the given id in the database.

3 Likes

You are also using Phoenix 1.2, You should upgrade and use phx generator instead of phoenix generator.

1 Like

Now I see it - all of my database entries were well above the number range I thought they were. Thanks!