Add data to schema column from form

I have confused with the phoenix docs, hope someone here to answer my basic questions :slight_smile:

So, If We have a migrated schema called players with a column :name, how we have to built a form with whom we can add data to this field :name (string)? The point is that how do we call the function to record the data to the exactly this schema players? I have tried (based on a different CRUD resource) creating a:

<%= form_for @changeset, @action, [multipart: true], fn f -> %>

<%= text_input f, :name %>


changeset = Home.change_players(%Players{})


def change_players(%Players{} = players, attrs \\ %{}) do
  Players.changeset(players, attrs)

but obviously its not like that

Best Regards

I think you wanted to use the cast function here:

def change_players(%Players{} = players, attrs \\ %{}) do
  Ecto.Changeset.cast(players, attrs)

I encourage you to read through the Getting Started guide of Ecto.

1 Like