Parcourir la source

works better; still weird

jordan il y a 3 ans
Parent
commit
2ffebe2966

+ 1 - 2
lib/fourletters/troll.ex

@@ -7,8 +7,7 @@ defmodule Fourletters.Troll do
   @impl true
   def init(_arg) do
     children = [
-      %{id: :butt, 
-        start: {ABCD.Fourletters, :start_link, [["yo"]]}}
+      %{id: :butt, start: {ABCD.Fourletters, :start_link, [["yo"]]}}
     ]
 
     Supervisor.init(children, strategy: :one_for_one)

+ 10 - 1
lib/fourletters_web/controllers/fourletters_controller.ex

@@ -3,6 +3,7 @@ defmodule FourlettersWeb.FourlettersController do
   import Fourletters.Troll
   import ABCD.Fourletters
 
+
   def fourletters(conn, %{"fourletters" => fourletters}) do
     if String.length(fourletters) == 4 do
 
@@ -19,6 +20,7 @@ defmodule FourlettersWeb.FourlettersController do
     end
   end
 
+
   def addletters(conn, _params) do
     %{params: params, path_params: path_params} = conn
     %{"fourletters" => fourletters, "message" => message} = params
@@ -31,12 +33,19 @@ defmodule FourlettersWeb.FourlettersController do
         {:error, {:already_started, pid}} -> pid
       end
       messages = ABCD.Fourletters.put(pid, message)
-      json(conn, %{fourletters: fourletters, messages: messages})
+      messages = ABCD.Fourletters.get(pid)
+      conn
+      |> put_status(:created)
+      # |> json(%{fourletters: fourletters, messages: messages})
+      # |> put_status(:ok)
+      |> redirect(to: "/#{fourletters}")
+      # |> render("four.html", fourletters: fourletters, messages: messages)
     else
       json(conn, %{error: message})
     end
   end
 
+
   def nothing(conn, _params) do
     render(conn, "nothing.html")
   end

+ 0 - 2
lib/fourletters_web/router.ex

@@ -18,8 +18,6 @@ defmodule FourlettersWeb.Router do
 
     get "/", FourlettersController, :nothing
     get "/:fourletters", FourlettersController, :fourletters
-    # get "/fourletters", FourlettersController, :index
-    # get "/fourletters/:messenger", FourlettersController, :show
   end
 
   # Other scopes may use custom stacks.

+ 6 - 0
lib/fourletters_web/templates/fourletters/four.html.eex

@@ -1,4 +1,10 @@
 <h1>hey <%= @fourletters %></h1>
+<form action="" method="post">
+	<label for="message">message:</label><br>
+	<input type=”text” id="message" name="message"><br><br>
+	<input type="submit" value="Submit">
+</form>
+
 <ul>
 	<%= for message <- @messages do %>
 	<li>