small medium large xlarge

Generic-user-small
03 Apr 2018, 21:54
Michael Haggerty (2 posts)

Following the examples in the book, running into the following error:

  ** (FunctionClauseError) no function clause matching in Ecto.Changeset.cast_key/1

This happens every time I load the manage/videos/new page.

The stacktrace points to the model for videos. Here’s what that looks like:

defmodule BmdBackend.Video do
  use BmdBackend.Web, :model

  schema "videos" do
    field :url, :string
    field :title, :string
    field :description, :string
    belongs_to :user, BmdBackend.User

    timestamps()
  end

  @doc """
  Builds a changeset based on the `struct` and `params`.
  """
  @required_fields ~w(url title description)
  @optional_fields ~w()

  def changeset(struct, params \\ %{}) do
    struct
    |> cast(params, [params, @required_fields, @optional_fields])
    |> validate_required([:url, :title, :description])
  end
end
You must be logged in to comment