["html"] plug :fetch_session plug :fetch_flash plug :protect_from_forgery end pipeline :api do plug :accepts, ["json"] plug :Blog.Plug.Authentication end scope "/", Blog do pipe_through :browser # Use the default browser stack get "/", PageController, :index end scope "/api", Blog.Api, as: :api do pipe_through :api # Use the API stack resources "/posts", PostController, only: [:index, :show] end end
index(conn, %{"category" => category}) do posts = Blog.Post.find_by_category(category) render conn, "index.html", posts: posts end def index(conn, _params) do render conn, "index.html", posts: Blog.Post.all end def show(conn, %{"id" => id}) do post = Blog.Post.find(id) render conn, "show.html", post: post end end
join("rooms:lobby", _message, socket) do {:ok, socket} end def join("rooms:" <> _private_room_id, _message, _socket) do :ignore end def handle_in("new_msg", message, socket) do broadcast!(socket, "new_msg", %{username: message["username"], body: message["body"]}) {:noreply, socket} end end