how to execute an action if the before_action returns false

后端 未结 3 1241
感情败类
感情败类 2021-01-04 04:39

I know that with the following code:

before_action :signed_in?, only: [:new]

the action new will be executed if the signed_in

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-04 05:20

    before_action :new, unless: -> { signed_in? }
    

    alltough i think its better to redirect in the action which was called.

    def your_action_called
      redirect_to :new unless signed_in?
      [...code ...]
    end
    

提交回复
热议问题