0

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.

spectatorx
  • 373
  • 2
  • 7
  • 22

1 Answers1

2

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.

Daniel
  • 2,320
  • 1
  • 14
  • 27
  • Thank you a lot! Unfortunately i am aware elixir and phoenix are fairly young (or not so much if you take a look at elixir as a... "variation" of erlang) and there is not many materials covering this language and framework and keeping with changes in them. Anyway, your answer helped me. – spectatorx Jan 03 '20 at 23:33
  • the best material is the documentation itself, try to read more often and you will find just how good it is. – Daniel Jan 03 '20 at 23:41
  • @spectatorx, Periodically you can pick up `Phoenix in Action` at a 50% discount, which is $20 US for the digital version. See here: https://elixirforum.com/t/book-sales-discounts-coupons-thread/2158/137 – 7stud Jan 04 '20 at 11:21
  • I dunno, I'm literally reading the documentation itself, and even though it's the docs for the latest version, it still seems to omit this context parameter. :/ – Hakanai Dec 07 '20 at 22:38