I’m going through the examples on the drab page. In the ‘chat example’ section, in the code example.
defhandler update_chat(socket, sender) do
nick = get_store(socket, :nickname, "Anonymous")
html = ~E"<strong><%= nick %>:</strong> <%= message %><br>" |> safe_to_string()
broadcast_insert socket, "#chat", :beforeend, html
set_prop socket, this(sender), value: ""
broadcast_js socket, "document.querySelector('#chat').scrollTop =
document.querySelector('#chat').scrollHeight"`
end
On the third line, the one with html, a sigil ~E is used. I don’t know what this does, and it doesn’t show up in the elixir docs or in the page source code. Anyone know what this is?
Tried to call module.function, that gave page_commander.ex:14: undefined function sigil_E/2.
Now, page_commander.ex:16: undefined function message/0
it’s the 3rd line in
defhandler update_chat(socket, sender) do
nick = get_store(socket, :nickname, "Anonymous")
html = ~E"<strong><%= nick %>:</strong> <%= message %><br>" |> safe_to_string()
defmodule AppWeb.PageCommander do
use Drab.Commander #, modules: [Drab.Presence]
import Phoenix.HTML
import Drab.Presence
gives error:
** (CompileError) lib/olist_no_brunch_web/commanders/page_commander.ex:4: module Drab.Presence is not loaded and could not be found
(stdlib) erl_eval.erl:677: :erl_eval.do_apply/6
Yes, that page was my reference, but I couldn’t find the difference.
The only 1 I see now is that you are using own module to store data worker(DrabPoc.Presence, []), but the app should work w/o it.
After your instructions had same error.
Removed _build dir, restarted app, and now it works!
Oops, this is bad, it shouldn’t be like this.
Compilation of Drab.Presence depends on the config options, this must be an issue. I will try to hunt it down.
@grych debug info: I was done with Chat Example in https://tg.pl/drab and it was working fine.
Then I started adding Presence and got into trouble until removing the build.
Thanks for Drab - I am really enjoying it. I wanted to ask if this issue with Drab.Presence had been resolved. I am using 0.10.1 (Phoenix 1.4) and wonder if I have the same problem.
For example, if I create a stock app “my_app” (mix phx.new my_app), and do the following (let me apologize now if I am missing/screwing up a step):
add {:drab, "~> 0.10.1"} to config.exs
mix deps.get
mix drab.install
mix drab.gen.commander Page
add config :drab, :presence, true to config.exs
add Drab.Presence to my supervision tree in lib/my_app/application.ex
add import Drab.Presence to page_commander.ex
I get the error below when I run mix phx.server:
(CompileError) lib/my_app_web/controllers/page_controller.ex:3:
module Drab.Presence is not loaded and could not be found
From this point if I rm -rf _build and mix phx.server again, everything recompiles and I get the same error.
Yes and no. I did the steps (edited below to be more accurate) and I get the same error. However - this time I did rm -rf _build and then when I restarted the server it recompiled with no error. That works for me!
That said - please let me re-document my steps as I did not record them 100% correctly the first time. I am using Phoenix 1.4, Elixir 1.7.4, Erlang/OTP 21.
mix phx.new my_app --no-ecto
add {:drab, "~0.10.1"} to mix.exs
mix deps.get
mix drab.install
mix drab.gen.commander Page
add config: drab, :presence, true to config.exs
add Drab.Presence to my supervision tree in lib/my_app/application.ex
add import Drab.Presence to page_commander.ex
note that config: Drab, MyAppWeb.Endpoint, otp_app: my_app is in config.exs
run mix phx.server
I deviated from the instructions in the docs in two respects:
The docs say to modify the supervision tree in lib/my_app_web.ex; I’m assuming that where the supervision tree was specified in an older version of Phoenix?
The docs say to make sure that config: Drab, MyAppWeb.Endpoint, otp_app: my_app_web is set, not my_app, which is what was inserted into my file by the generator. I admit I don’t really understand what that is doing. I did modify it to my_app_web and get the same error, for what that is worth.