Remove stream at the class level.

This is because only template rendering works with streaming.
Setting it at the class level was also changing the behavior
of JSON and XML responses, closes #1337.
This commit is contained in:
José Valim 2011-07-06 20:24:15 -03:00
parent 689c3d674c
commit 7da88c5b29
2 changed files with 6 additions and 39 deletions

@ -24,20 +24,8 @@ module ActionController #:nodoc:
# #
# == Examples # == Examples
# #
# Streaming can be added to a controller easily, all you need to do is # Streaming can be added to a given template easily, all you need to do is
# call +stream+ in the controller class: # to pass the :stream option.
#
# class PostsController
# stream
# end
#
# The +stream+ method accepts the same options as +before_filter+ and friends:
#
# class PostsController
# stream :only => :index
# end
#
# You can also selectively turn on streaming for specific actions:
# #
# class PostsController # class PostsController
# def index # def index
@ -72,6 +60,9 @@ module ActionController #:nodoc:
# render :stream => true # render :stream => true
# end # end
# #
# Notice that :stream only works with templates. Rendering :json
# or :xml with :stream won't work.
#
# == Communication between layout and template # == Communication between layout and template
# #
# When streaming, rendering happens top-down instead of inside-out. # When streaming, rendering happens top-down instead of inside-out.
@ -209,33 +200,9 @@ module Streaming
extend ActiveSupport::Concern extend ActiveSupport::Concern
include AbstractController::Rendering include AbstractController::Rendering
attr_internal :stream
module ClassMethods
# Render streaming templates. It accepts :only, :except, :if and :unless as options
# to specify when to stream, as in ActionController filters.
def stream(options={})
if defined?(Fiber)
before_filter :_stream_filter, options
else
raise "You cannot use streaming if Fiber is not available."
end
end
end
protected protected
# Mark following render calls as streaming.
def _stream_filter #:nodoc:
self.stream = true
end
# Consider the stream option when normalazing options.
def _normalize_options(options) #:nodoc:
super
options[:stream] = self.stream unless options.key?(:stream)
end
# Set proper cache control and transfer encoding when streaming # Set proper cache control and transfer encoding when streaming
def _process_options(options) #:nodoc: def _process_options(options) #:nodoc:
super super

@ -10,9 +10,9 @@ class BasicController < ActionController::Base
)] )]
layout "application" layout "application"
stream :only => [:hello_world, :skip]
def hello_world def hello_world
render :stream => true
end end
def layout_exception def layout_exception