Developing With Elixir (Pragmatic Studio)



So for me (a beginner) which one of these you recommend? I already bought the bingo course.


I think either could serve your needs. I enjoy the Pragmatic Studio because I like the silliness between Mike and Nicole as work their way along. Dave Thomas is very smart, but since he’s by himself he’s not quite as entertaining.


I’m following the same course. At one point when they’re reading the about.html file, they typed the path as “../../page/about.html”, because the handler.ex file lives 2 levels down than the root.
Here is the screenshot.

When I did the same, it gave me :enoent (file not found), but when I typed the path as “pages/about.html”, it worked.
Is there anything changed in BEAM that it now handles files paths differently? (or what they did differently?)

Here is the function:

  def route(%{method: "GET", path: "/about"} = conv) do
    case"pages/about.html") do
      {:ok, content} ->
        %{conv | status: 200, resp_body: content}

      {:error, :enoent} ->
        %{conv | status: 404, resp_body: "File not found!"}

      {:error, reason} ->
        %{conv | status: 500, resp_body: "File error: #{reason}"}

And here is the files and folders structure:

├── config
│   └── config.exs
├── lib
│   ├── servy
│   │   └── handler.ex
│   └── servy.ex
├── mix.exs
├── pages
│   └── about.html
└── test
    ├── servy_test.exs
    └── test_helper.exs


Elixir has a concept of the current working directory that relative paths are resolved against. Perhaps Mike an Nicole we’re running the application from a different path than you were.


I first tried the way they taught and it gave me an error with the reason :enoent then I removed the ../../ part from it, and it worked.
Now I don’t know, why it worked this ( case"pages/about.html") do )
way, because if you look at the directory structure, it should work the way Nicole and Mike taught ( case"../../pages/about.html") do ).

Edit: The only difference in our setups is that they’re running the script inside Sublime, and I have coderunner extension installed in VSCode, which does the job.


I even ran it from the terminal, being in the root of the project I ran elixir lib/servy/handler.ex, still it worked without ../../

Thank you for the reply!


I don’t use Sublime for Elixir development, but looks like Sublime takes the current directory from the file being run, and VSCode takes the project’s root as the current directory. Simple!
And that’s what @easco also said.


I watched that video further and they explained the same in the video. Thank you @DevotionGeo and @easco!