Rails3 Rack response - undefined response.body method

  def call(env)
    status, headers, response = @app.call(env)

    if response.is_a? Array
      puts response.inspect
    else
      puts response.class.to_s
    end

    [status, headers, response]
  end

From development.log:

First request:

Completed 200 OK in 95ms (Views: 35.9ms | ActiveRecord: 1.5ms)
ActionDispatch::Response

Second and other queries:

Completed 200 OK in 77ms (Views: 76.3ms | ActiveRecord: 0.0ms)
[]

Answer: the ActionDispatch::Responsefirst time the route is called, for any other requests for this exact URL it is emptyArray

The page succeeds in both cases, but I cannot use response.bodyit when the response is an empty array.

Is this normal Rails behavior? Is there caching here even in dev environment?

+3
source share
1 answer

I see the same thing.

, HTTP (200 OK), (304, " ". )

304 , , . GET ( ?) . , , , .

, , CTRL-F5 ( Firefox), " ". , GET .

, , , ( ruby-debug).

def call(env)
  status, headers, response = @app.call(env)
  debugger
  if headers["Content-Type"].include?("text/html")
    [status, headers, "<!--hello world! -->" + response.body]
  else
    [status, headers, response]
  end
end

rail server:

(rdb:1) irb
irb(#<PostRedirect:0x7f9c6292a530>):001:0> status
=> 304

, :

  if (status != 304) && headers["Content-Type"].include?("text/html")
+1

Source: https://habr.com/ru/post/1781125/


All Articles