Ruby on rails redirect_to

时间:2010-12-11 10:29:45

标签: ruby-on-rails

这是什么意思?   redirect_to“”并返回

1 个答案:

答案 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