0
votes

I'm trying to learn elixir and phoenix off this video: https://www.youtube.com/watch?v=KiP23mk760E&list=PLtTtLKRL6UYGxOHToRYnXBynon5plZ7Jd&index=2 which despite being fairly fresh seems to be outdated on some info. For example "mix phoenix.gen.html" got replaced with "mix phx.gen.html" and that's what i'm struggling with at the moment. In video is shown command:

mix phoenix.gen.html Post posts title:string body:text

But when i try to execute: mix phx.gen.html Post posts title:string body:text I'm getting an error starting with: "(Mix) Expected the schema, "posts", to be a valid module name" and i'm lost in here. I've read documentation for phx.gen.html but this didn't help me much as i have no idea what module should i use. I tried to use --no-context but this didn't help, i'm still getting the same error. Basically my question is: how to use phx.gen.html in order to let me continue with that tutorial.

1

1 Answers

1
votes

Since elixir is a very young language, videos from 2017 are outdated, a lot of infrastructure changed since then. At this point in time elixir and phoenix are pretty stable and at least elixir won't receive any more breaking changes, however old videos won't help you much.

Notion of contexts was introduced in phoenix to replace the models structure. The idea behind it is that you don't put all your schemas in a model folder, however you group a bunch of schemas in a Context, witch is a common domain, you can listen more about how this works from the original creator of phoenix.

To make it more clear, definitions for gen now go like this:

mix phx.gen.html [Context] [Schema name] [Table name] [Fields] ...

So basically you just need to add your context before everything else like so:

mix phx.gen.html Articles Post posts title:string body:text

PS: Instead of following that outdated series, just watch some conferences where people teach how to use things like Ecto, this one is especially good since it makes a clear separation between what Ecto represents by not including phoenix into the project.