redirect_to != return

后端 未结 6 1409
陌清茗
陌清茗 2020-12-07 22:13

I\'m looking for some clarification regarding the behaviour of redirect_to.

I have this code:

if some_condition
   redirect_to(path_one)         


        
6条回答
  •  北荒
    北荒 (楼主)
    2020-12-07 22:35

    From http://api.rubyonrails.org/classes/ActionController/Base.html:

    If you need to redirect on the condition of something, then be sure to add “and return” to halt execution.

    def do_something
      redirect_to(:action => "elsewhere") and return if monkeys.nil?
      render :action => "overthere" # won't be called if monkeys is nil
    end
    

提交回复
热议问题