答案 0 :(得分:5)
根据rails API文档:返回部分停止执行其他任何操作。换句话说,如果你有下面的文本将永远不会打印因为return语句。
def go_home
redirect_to(:action => "home") and return
puts "This will never print"
end
在下一个示例and return
中,只调用if 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
来自:http://api.rubyonrails.org/classes/ActionController/Base.html