Ruby on rails RubyonRails将您重定向到

Ruby on rails RubyonRails将您重定向到,ruby-on-rails,Ruby On Rails,这是什么意思? 根据rails API文档重定向到并返回:返回部分停止执行任何其他操作。换句话说,如果你有下面的文本,文本将永远不会打印,因为返回语句 def go_home redirect_to(:action => "home") and return puts "This will never print" end 在下一个示例中,仅当monkeys.nil?这是真的 def do_something redirect_to(:action =>

这是什么意思?
根据rails API文档重定向到并返回

:返回部分停止执行任何其他操作。换句话说,如果你有下面的文本,文本将永远不会打印,因为返回语句

def go_home
    redirect_to(:action => "home") and return
    puts "This will never print"
  end
在下一个示例中,仅当monkeys.nil?这是真的

 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:

根据rails API文档:返回部分停止执行任何其他操作。换句话说,如果你有下面的文本,文本将永远不会打印,因为返回语句

def go_home
    redirect_to(:action => "home") and return
    puts "This will never print"
  end
在下一个示例中,仅当monkeys.nil?这是真的

 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:

注意,这个习惯用法利用了布尔and表达式的短路求值。如果redirect_to返回false,Ruby将接受短路,并且不会费心计算表达式的其余部分;但是,如果redirect_to返回true,则必须计算表达式的其余部分。由于其余部分是return,整个表达式的效果是:发出重定向302代码,如果真的发生了这种情况,则返回而不采取任何其他操作。请注意,此习惯用法利用了布尔and表达式的短路求值。如果redirect_to返回false,Ruby将接受短路,并且不会费心计算表达式的其余部分;但是,如果redirect_to返回true,则必须计算表达式的其余部分。由于其余部分是return,整个表达式的作用是:发出重定向302代码,如果真的发生了这种情况,则返回而不采取任何其他操作。另请参见