clawblue
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!
Marked As Solved
NobbZ
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.
Also Liked
kokolegorille
You are also using Phoenix 1.2, You should upgrade and use phx generator instead of phoenix generator.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance










