Reputation: 45
I'm going through the book "Programming Phoenix" and after adding the /Users/New route around page 60, my router seems to have stopped functioning properly.
When I try to navigate to any /Users route I get
"no route found for GET /Users (Rumbl.Router)"
my router.ex file looks like this:
defmodule Rumbl.Router do
use Rumbl.Web, :router
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
end
pipeline :api do
plug :accepts, ["json"]
end
scope "/", Rumbl do
pipe_through :browser # Use the default browser stack
get "/", PageController, :index
resources "/users", UserController, only: [:index, :show, :new, :create]
end
end
My controller looks like this:
defmodule Rumbl.UserController do
use Rumbl.Web, :controller
alias Rumbl.User
def index(conn, _params) do
users = Repo.all(User)
render conn, "index.html", users: users
end
def show(conn, %{"id" => id}) do
user = Repo.get(User, id)
render conn, "show.html", user: user
end
def new(conn, _params) do
changeset = User.changeset(%User{})
render conn, "new.html", changeset: changeset
end
end
running "mix phoenix.routes" returns:
page_path GET / Rumbl.PageController :index
user_path GET /users Rumbl.UserController :index
user_path GET /users/new Rumbl.UserController :new
user_path GET /users/:id Rumbl.UserController :show
user_path POST /users Rumbl.UserController :create
It worked fine up until adding the "new" route. I've tried removing the new route(and everything that came with it) and going back to the way it was before with just
get "/users", UserController, :index
get "/users/:id", UserController, :show
and it still doesn't work.
I've restarted the phoenix server and tried recreating the router.ex file from scratch. I'm at a loss, what could be going on here?
Here is the stack trace:
[debug] ** (Phoenix.Router.NoRouteError) no route found for GET /Users (Rumbl.Router)
(rumbl) web/router.ex:1: Rumbl.Router.__match_route__/4
(rumbl) lib/phoenix/router.ex:307: Rumbl.Router.call/2
(rumbl) lib/rumbl/endpoint.ex:1: Rumbl.Endpoint.plug_builder_call/2
(rumbl) lib/plug/debugger.ex:122: Rumbl.Endpoint."call (overridable 3)"/2
(rumbl) lib/rumbl/endpoint.ex:1: Rumbl.Endpoint.call/2
(plug_cowboy) lib/plug/cowboy/handler.ex:18: Plug.Adapters.Cowboy.Handler.upgrade/4
(cowboy) /Users/richardschmidt/Code/Elixir/rumbl/deps/cowboy/src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4
Upvotes: 0
Views: 1297
Reputation: 9841
/Users
and /users
are not the same.
Try to use downcased version of paths: /users
, /users/new
.
Upvotes: 1