开发者

Ruby on rails redirect_to

开发者 https://www.devze.com 2023-01-29 20:12 出处:网络
what does it mean ? redirect_to开发者_高级运维 \"\" and returnAccording to the rails API docs: the return portion stops execution of anything else. In other words if you had the below the text would n

what does it mean ? redirect_to开发者_高级运维 "" and return


According to the rails API docs: the return portion stops execution of anything else. In other words if you had the below the text would never print because of the return statement.

def go_home
    redirect_to(:action => "home") and return
    puts "This will never print"
  end

In the next example and return is called only if monkeys.nil? is true.

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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号