03 - redirecting to a different location.rb

来自「O Reilly Ruby Cookbook source code」· RB 代码 · 共 45 行

RB
45
字号
class BureaucracyController < ApplicationController  def index    redirect_to :controller => 'bureaucracy', :action => 'reservation_window'  end  def reservation_window    redirect_to :action => 'claim_your_form', :id => 123  end  def claim_your_form    redirect_to :action => 'fill_out_your_form', :id => params[:id]  end  def fill_out_your_form    redirect_to :action => 'form_processing'  end  def form_processing    redirect_to "http://www.dmv.org/"  endend#---"GET /bureaucracy HTTP/1.1" 302"GET /bureaucracy/reservation_window HTTP/1.1" 302"GET /bureaucracy/claim_your_form/123 HTTP/1.1" 302"GET /bureaucracy/fill_out_your_form/123 HTTP/1.1" 302"GET /bureaucracy/form_processing HTTP/1.1" 302#---class DangerController < ApplicationController  def index    redirect_to :action => 'safety' unless params[:i_like_danger]    do_something_dangerous  end  # ...end#---class DangerController < ApplicationController  def index    (redirect_to :action => 'safety' and return) unless params[:i_like_danger]    do_something_dangerous  endend#---

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?