Ruby on rails redirect_to

akh*_*hil 1 ruby-on-rails

这是什么意思 ?redirect_to""并返回

Aus*_*Lin 5

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

def go_home
    redirect_to(:action => "home") and return
    puts "This will never print"
  end
Run Code Online (Sandbox Code Playgroud)

在下一个示例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
Run Code Online (Sandbox Code Playgroud)

来自:http://api.rubyonrails.org/classes/ActionController/Base.html