Dispacher (Rails)

エラーログから追ってみる。

「/usr/lib/ruby/gems/1.8/gems/rails-0.14.4/lib/dispatcher.rb」

どうもこいつの所でエラってるらしい。

「Class Dispacher」の冒頭に記述してあるものが以下

This class provides an interface for dispatching a CGI (or CGI-like) request to the appropriate controller and action. It also takes care of resetting the environment (when Dependencies.load? is true) after each request.

dispacheメソッドの前に記述してあるものが以下

Dispatch the given CGI request, using the given session options, and emitting the output via the given output. If you dispatch with your
own CGI object be sure to handle the exceptions it raises on multipart requests (EOFError and ArgumentError).

で、本体が以下となる。

def dispatch(cgi = nil, session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, output = $stdout)
if cgi ||= new_cgi(output)
request, response = ActionController::CgiRequest.new(cgi, session_options), ActionController::CgiResponse.new(cgi)
prepare_application
ActionController::Routing::Routes.recognize!(request).process(request, response).out(output)
end
rescue Object => exception
failsafe_response(output, '500 Internal Server Error') do
ActionController::Base.process_with_exception(request, response, exception).out(output)
end
ensure
# Do not give a failsafe response here.
reset_after_dispatch
end

引数が以下の3つ

  1. cgi = nil,
  2. session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS,
  3. output = $stdout

実質的に受け取って処理しているものは、「$stdout」となる。

if cgi ||= new_cgi(output)


で、outputを引数にしたnew_cgiメソッドで初期化。
つまり、outputからnew_cgiが値を返せば真になる。

「new_cgi」の定義は下記となる。

64 def new_cgi(output)
65 failsafe_response(output, '400 Bad Request') { CGI.new }
66 end

(直接記述か・・・)
ここで、「failsafe_response」メソッドを呼んで{ CGI.new }へ渡して
いる。

90 def failsafe_response(output, status)
91 yield
92 rescue Object
93 begin
94 output.write "Status: #{status}\r\n"
95 rescue Object
96 end
97 end

で、引っかかったら、以下のようにrequestとresponseを生成。

request, response = ActionController::CgiRequest.new(cgi, session_options), ActionController::CgiResponse.new(cgi)


次にどこかで見たような気がしてならないメソッドが出てくる。

38 ActionController::Routing::Routes.recognize!(request).process(request, response).out(output)


あ、もう寝なきゃ。


参照:
http://www.ruby-lang.org/ja/man/index.cgi?cmd=view;name=%B1%E9%BB%BB%BB%D2%BC%B0