How do you make a new page for a scope?

My router currently looks like this:

scope "/", TaskAppWeb do
  pipe_through([:browser])

  resources("/classes", ClassController)
end

However, I want classes to be prefixed with /teacher/

So I tried to do something like this: scope "/teacher", TaskAppWeb do.

This gets me part of the way there, because the url for creating classes now looks like this: /teacher/classes

However, I want the route teacher/ to give me a homepage for teachers. Currently I get this:

no route found for GET /teacher (TaskAppWeb.Router)

Which of course makes sense since all I did was rename the scope, but how would I actually create this new page for the /teacher scope?

The documentation shows you can do something like this:
scope "/teacher", TaskAppWeb.Teacher, as: :teacher do

But it doesn’t elaborate on how to actually hook up a page to this? Sorry if it’s self explanatory, I am still a beginner.

Scopes is only for groups of routes, but they’re not routes themselves. You’ll need to create another get/post/… route within the scrope (with partial path /) to get an actual page at /teacher.

If I understand correctly, I would need to do something like this then:

scope "/", TaskAppWeb do
  pipe_through([:browser])

  get("/teacher", TeacherController, :index)
  resources("/classes", ClassController)
end

But in that case, the classes page would go back to this: /classes whereas I want it to be teacher/classes

How would I achieve that?

scope "/teacher", TaskAppWeb do
  pipe_through([:browser])

  get("/", TeacherController, :index)
  resources("/classes", ClassController)
end
3 Likes

Welp, I feel like an idiot but this seems to be exactly what I want. Thanks a bunch!