siepet

siepet

Forwarded route with scoped paths

Hello, I have an main application router, which routes to different contexts, ie:

scope "/users/:id", as: user do
  scope "/events", as: event do
    use Event.Router
  end

  scope "/contacts", as: :contact do
    use Contact.Router
  end
end

and each of contexts’ router has a defined macro like this:

defmacro __using__() do
  quote do
    scope "/", Event do
      get("/", EventController, :index)
    end
  end
end

And right now, I’m trying to switch this to Phoenix.Router — Phoenix v1.8.8
So I did this in main router:

scope "/users/:id", as: user do
  scope "/event", as: :event do
    forward "/event", Event.Router
  end
end

But with router as Event.Router is shown, it doesn’t work, because it won’t catch the :id from the parent router.

At first, I’ve tried this:

# Event.Router
 scope "/users/:id", Event do
   get("/", EventController, :index)
 end

But then it shows me this error:

** (Phoenix.Router.NoRouteError) no route found for GET /events (Event.Router)

and having this, fixes the error, but I don’t think this should be the solution:

# Event.Router
 get("/events", EventController, :index)
 scope "/users/:id", Event do
   get("/events", EventController, :index)
 end

What should be correct approach here?

First Post!

OvermindDL1

OvermindDL1

I’ve been curious in this too, would simplify things, right now I’m parsing the path after the fact, which is not very clean.

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

Other popular topics Top

grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54260 488
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New

We're in Beta

About us Mission Statement