aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-03-15 19:46:03 +0000
committerPratik Naik <pratiknaik@gmail.com>2010-03-15 19:46:03 +0000
commit03a62f4afedbef8bda72c8fdf9a0092273c0f2b0 (patch)
tree2155b65750757d26e3c8c8e0655ad32cc89d6c2e /actionpack/lib/action_controller
parentf53fddf3665e6582768f4ab0c82b286b39e7fb19 (diff)
parenta594a22267bfd3346e00923742c4aa7edad0cef7 (diff)
downloadrails-03a62f4afedbef8bda72c8fdf9a0092273c0f2b0.tar.gz
rails-03a62f4afedbef8bda72c8fdf9a0092273c0f2b0.tar.bz2
rails-03a62f4afedbef8bda72c8fdf9a0092273c0f2b0.zip
Merge remote branch 'mainstream/master'
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r--actionpack/lib/action_controller/base.rb8
-rw-r--r--actionpack/lib/action_controller/caching/fragments.rb12
-rw-r--r--actionpack/lib/action_controller/metal/mime_responds.rb1
-rw-r--r--actionpack/lib/action_controller/metal/renderers.rb3
-rw-r--r--actionpack/lib/action_controller/metal/rendering.rb21
5 files changed, 26 insertions, 19 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index fcd3cb9bd3..ad2b68af21 100644
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -2,7 +2,6 @@ module ActionController
class Base < Metal
abstract!
- include AbstractController::Callbacks
include AbstractController::Layouts
include AbstractController::Translation
@@ -23,6 +22,7 @@ module ActionController
# Rails 2.x compatibility
include ActionController::Compatibility
+ include ActionController::ImplicitRender
include ActionController::Cookies
include ActionController::Flash
@@ -36,8 +36,12 @@ module ActionController
# Add instrumentations hooks at the bottom, to ensure they instrument
# all the methods properly.
include ActionController::Instrumentation
- include ImplicitRender
+ # Before callbacks should also be executed the earliest as possible, so
+ # also include them at the bottom.
+ include AbstractController::Callbacks
+
+ # The same with rescue, append it at the end to wrap as much as possible.
include ActionController::Rescue
def self.inherited(klass)
diff --git a/actionpack/lib/action_controller/caching/fragments.rb b/actionpack/lib/action_controller/caching/fragments.rb
index bb5ff95a67..89787727bd 100644
--- a/actionpack/lib/action_controller/caching/fragments.rb
+++ b/actionpack/lib/action_controller/caching/fragments.rb
@@ -41,9 +41,7 @@ module ActionController #:nodoc:
else
pos = buffer.length
block.call
- content = buffer[pos..-1]
- content = content.as_str if content.respond_to?(:as_str)
- write_fragment(name, content, options)
+ write_fragment(name, buffer[pos..-1], options)
end
else
block.call
@@ -53,9 +51,10 @@ module ActionController #:nodoc:
# Writes <tt>content</tt> to the location signified by <tt>key</tt> (see <tt>expire_fragment</tt> for acceptable formats)
def write_fragment(key, content, options = nil)
return content unless cache_configured?
- key = fragment_cache_key(key)
+ key = fragment_cache_key(key)
instrument_fragment_cache :write_fragment, key do
+ content = content.html_safe.to_str if content.respond_to?(:html_safe)
cache_store.write(key, content, options)
end
content
@@ -64,10 +63,11 @@ module ActionController #:nodoc:
# Reads a cached fragment from the location signified by <tt>key</tt> (see <tt>expire_fragment</tt> for acceptable formats)
def read_fragment(key, options = nil)
return unless cache_configured?
- key = fragment_cache_key(key)
+ key = fragment_cache_key(key)
instrument_fragment_cache :read_fragment, key do
- cache_store.read(key, options)
+ result = cache_store.read(key, options)
+ result.respond_to?(:html_safe) ? result.html_safe : result
end
end
diff --git a/actionpack/lib/action_controller/metal/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb
index e70a20b2be..2ac199265d 100644
--- a/actionpack/lib/action_controller/metal/mime_responds.rb
+++ b/actionpack/lib/action_controller/metal/mime_responds.rb
@@ -261,6 +261,7 @@ module ActionController #:nodoc:
block.call(collector) if block_given?
if format = request.negotiate_mime(collector.order)
+ self.content_type ||= format.to_s
self.formats = [format.to_sym]
collector.response_for(format)
else
diff --git a/actionpack/lib/action_controller/metal/renderers.rb b/actionpack/lib/action_controller/metal/renderers.rb
index 49d3d6b466..08325b468c 100644
--- a/actionpack/lib/action_controller/metal/renderers.rb
+++ b/actionpack/lib/action_controller/metal/renderers.rb
@@ -87,8 +87,9 @@ module ActionController
end
add :update do |proc, options|
+ _evaluate_assigns(view_context)
generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(view_context, &proc)
- self.content_type = Mime::JS
+ self.content_type = Mime::JS
self.response_body = generator.to_s
end
end
diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb
index f892bd9b91..86bb810947 100644
--- a/actionpack/lib/action_controller/metal/rendering.rb
+++ b/actionpack/lib/action_controller/metal/rendering.rb
@@ -5,26 +5,31 @@ module ActionController
include ActionController::RackDelegation
include AbstractController::Rendering
- def process(*)
+ # Before processing, set the request formats in current controller formats.
+ def process_action(*) #:nodoc:
self.formats = request.formats.map { |x| x.to_sym }
super
end
- def render(*args)
+ # Check for double render errors and set the content_type after rendering.
+ def render(*args) #:nodoc:
raise ::AbstractController::DoubleRenderError if response_body
super
+ self.content_type ||= Mime[formats.first].to_s
response_body
end
private
- def _normalize_args(action=nil, options={}, &blk)
+ # Normalize arguments by catching blocks and setting them on :update.
+ def _normalize_args(action=nil, options={}, &blk) #:nodoc:
options = super
options[:update] = blk if block_given?
options
end
- def _normalize_options(options)
+ # Normalize both text and status options.
+ def _normalize_options(options) #:nodoc:
if options.key?(:text) && options[:text].respond_to?(:to_text)
options[:text] = options[:text].to_text
end
@@ -36,7 +41,8 @@ module ActionController
super
end
- def _process_options(options)
+ # Process controller specific options, as status, content-type and location.
+ def _process_options(options) #:nodoc:
status, content_type, location = options.values_at(:status, :content_type, :location)
self.status = status if status
@@ -46,10 +52,5 @@ module ActionController
super
end
- def _with_template_hook(template)
- super
- self.content_type ||= template.mime_type.to_s
- end
-
end
end