Rails' before_filter equivalent in Phoenix

前端 未结 2 2023
轮回少年
轮回少年 2021-01-04 03:30

I\'ve just started working on my first Phoenix app, and the issue is that I have some common lines of code in every action in my controller, that I would like to separate ou

2条回答
  •  情深已故
    2021-01-04 04:00

    This is better as a comment but I lack the rep; with the current version of Phoenix (1.3.4, August of 2018), if you use the top answer's code, you would only want to do plug :store_something: do not use plug :action as it is redundant. The actions will run after the plugs which you listed.

    If you include plug :action you will get (Plug.Conn.AlreadySentError) the response was already sent as the action will run twice and Phoenix will be mad at you.

提交回复
热议问题