Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Routing 有没有办法只为一条线路安装一个Phoenix插头?_Routing_Elixir_Phoenix Framework_Plug - Fatal编程技术网

Routing 有没有办法只为一条线路安装一个Phoenix插头?

Routing 有没有办法只为一条线路安装一个Phoenix插头?,routing,elixir,phoenix-framework,plug,Routing,Elixir,Phoenix Framework,Plug,在凤凰城,我的路线如下: scope "/", ManaWeb do pipe_through [:browser, :auth] get "/register", RegistrationController, :new post "/register", RegistrationController, :register end 不过,我想为最后一条路线(POST)设置一个插头 我将如何使用当前的工具来实现这一点?正如 每次调用pipe_至/1,新管道都会

在凤凰城,我的路线如下:

  scope "/", ManaWeb do
    pipe_through [:browser, :auth]
    get "/register",  RegistrationController, :new
    post "/register", RegistrationController, :register
  end
不过,我想为最后一条路线(POST)设置一个插头


我将如何使用当前的工具来实现这一点?

正如

每次调用
pipe_至/1
,新管道都会附加到先前给定的管道上

也就是说,这将起作用:

scope/,ManaWeb do
管道通过[:浏览器,:验证]
获取“/注册”,注册控制器:新建
管道:柱塞
post“/寄存器”,注册控制器:寄存器
结束

另一种解决方案是直接在控制器中使用插头

defmodule ManaWeb.RegistrationController do
  # import the post_plug...
  plug :post_plug when action in [:register]

  def register(conn, params) do
    # ...
  end
end

请记住,您在
管道下方放置的任何路线通过:post\u plug
都将调用
:post\u plug
。我认为这比我的建议更优雅。管道方法对我来说已经足够好了,这非常有趣,因为il允许在控制器中设置每个路由的插头。这在什么地方有记录吗?@thodg它应该在官方文件的某个地方,但我在凤凰城的编程书中读到过