Elixir 在Phoenix中使用插头执行特定操作

Elixir 在Phoenix中使用插头执行特定操作,elixir,phoenix-framework,Elixir,Phoenix Framework,如何使用插件在phoenix上执行特定操作。如果想在特定操作中使用插件,或者相反,不想在特定操作中使用插件如文档中所述,我们可以使用保护子句 plug/2支持保护,允许开发人员将插件配置为仅在某些特定操作中运行 第一个插件仅在显示或编辑操作时运行。除索引操作外,第二个插件将始终运行 我在搜索了一下后发现了这个。这让我找到了医生。希望它能帮助别人 plug :log_message, "before show and edit" when action in [:show, :

如何使用插件在phoenix上执行特定操作。如果想在特定操作中使用插件,或者相反,想在特定操作中使用插件

如文档中所述,我们可以使用保护子句

plug/2支持保护,允许开发人员将插件配置为仅在某些特定操作中运行

第一个插件仅在显示或编辑操作时运行。除索引操作外,第二个插件将始终运行

我在搜索了一下后发现了这个。这让我找到了医生。希望它能帮助别人

plug :log_message, "before show and edit" when action in [:show, :edit]
plug :log_message, "before all but index" when not action in [:index]
# or
plug :log_message, "before all but index" when action not in [:index]