fourletters_controller.ex 905 B

1234567891011121314151617181920212223242526272829
  1. defmodule FourlettersWeb.FourlettersController do
  2. use FourlettersWeb, :controller
  3. import Fourletters.Troll
  4. import ABCD.Fourletters
  5. def fourletters(conn, %{"messenger" => messenger}) do
  6. if String.length(messenger) == 4 do
  7. {:ok, sup_pid} = Supervisor.start_link(Fourletters.Troll, [])
  8. pid = case Supervisor.start_child(
  9. sup_pid, %{id: String.to_atom(messenger),
  10. start: {ABCD.Fourletters, :start_link, [[]]}}) do
  11. {:ok, pid} -> pid
  12. {:error, {:already_started, pid}} -> pid
  13. end
  14. messages = ABCD.Fourletters.get(pid)
  15. render(conn, "four.html", messenger: messenger, messages: messages)
  16. end
  17. redirect(conn, to: "/")
  18. end
  19. # def fourletters(conn, %{"messenger" => messenger}) do
  20. # render(conn, "nothing.html")
  21. # end
  22. def nothing(conn, _params) do
  23. render(conn, "nothing.html")
  24. end
  25. end