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
Elixir 模块插头的防护装置?_Elixir_Phoenix Framework - Fatal编程技术网

Elixir 模块插头的防护装置?

Elixir 模块插头的防护装置?,elixir,phoenix-framework,Elixir,Phoenix Framework,请原谅我的新手问题,但是我发现了很多保护功能的例子,比如: plug :assign_welcome_message, "Hi!" when action in [:index, :show] 但我没有发现如何使用模块插头执行此操作的示例: plug Guardian.Plug.EnsurePermissions, handler: Mp.Api.AuthController, admin: [:dashboard] when action in [:protected_action]

请原谅我的新手问题,但是我发现了很多保护功能的例子,比如:

plug :assign_welcome_message, "Hi!" when action in [:index, :show]
但我没有发现如何使用模块插头执行此操作的示例:

plug Guardian.Plug.EnsurePermissions,
  handler: Mp.Api.AuthController,
  admin: [:dashboard] when action in [:protected_action]
当[:protected\u action]中的操作时,我似乎移动到了
的任何地方。
要么给我一个语法错误,要么给我一个未定义的函数
when/2
。我知道我在做傻事,但我看不出是什么

救命啊



凤凰城1.1.4

不傻!只是一些语法上的甜言蜜语的结果

,第二个是选项的参数。在您的示例中,您希望传递一个关键字列表作为选项参数

但是,仅当关键字列表是函数中的最后一个参数时,此选项才起作用

而不是

plug Guardian.Plug.EnsurePermissions,
  handler: Mp.Api.AuthController,
  admin: [:dashboard] when action in [:protected_action]
尝试显式关键字列表语法:

plug Guardian.Plug.EnsurePermissions,
  [handler: Mp.Api.AuthController,
  admin: [:dashboard]] when action in [:protected_action]

这在我的路由器管道中给了我同样的编译错误,但在控制器中工作。你知道为什么吗?使用phoenix 1.3。0@Johannes我也有同样的问题。您找到解决方案了吗?如果您查看源代码,
Phoenix.Controller.Pipeline
被编程为编译防护(如
Plug.Builder
),但
Phoenix.Router
没有。