Developing With Elixir (Pragmatic Studio)

video-course
pragmatic-studio
Tags: #<Tag:0x00007f8ea6953c88> #<Tag:0x00007f8ea6953878>

#21

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


#22

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.


#23

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.
elixir

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 File.read("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}"}
    end
  end

And here is the files and folders structure:

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

#24

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.


#25

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 File.read("pages/about.html") do )
way, because if you look at the directory structure, it should work the way Nicole and Mike taught ( case File.read("../../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.

Edit2:

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!


#26

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.


#27

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