the model is simple. The project is MagazijnWeb and there’s the model direct under.
defmodule Category do
use Ecto.Schema
import Ecto.Changeset
schema "category" do
field :category, :string
end
def changeset(category, params \\ %{}) do
category
|> cast(params,[:category])
|> validate_required([:category])
end
Your module name is defined as Category, not MagazijnWeb.Category.
If you generated it from the command line through one of the phx.gen.* tasks it would have been called Magazijn.Category, without the “Web” part, and put under lib/magazijn/ to make it clear it is part of the core logic, separated from the web functionality.
alias MagazijnWeb.Category is trying to find a module defined as defmodule MagazijnWeb.Category do
If you remove the alias your current code trying to call Category.changeset should work, but I suggest you read up on Phoenix directory structure
Can you post the stacktrace or error message in the Topic/Post instead of making it the title.
You can format the code using using code blocks by wrapping in 3 backticks as below:
```
Insert Your code Here
```
Error message which was in title
lib/magazijn_web/controllers/category_controller.ex:7:
MagazijnWeb.Category.__struct__/1 is undefined, cannot expand struct MagazijnWeb.Category.
Make sure the struct name is correct. If the struct name exists and is correct but it still cannot be found,
Welcome to the forum. can you please show the error? The problem I found in your code yet is that you have defined the schema module in the wrong way. it should be like this;
defmodule Magazijn.Category do instead of defmodule Category do
OR
you can also create all of your models schema by creating a directory in Magazijn such as, defmodule Magazijn.Models.Category do.