mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Flash shouldnt depend on components either [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3581 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
050c3964d8
commit
ff986f19af
2 changed files with 40 additions and 14 deletions
|
@ -51,6 +51,9 @@ module ActionController #:nodoc:
|
||||||
|
|
||||||
alias_method :set_session_options_without_components, :set_session_options
|
alias_method :set_session_options_without_components, :set_session_options
|
||||||
alias_method :set_session_options, :set_session_options_with_components
|
alias_method :set_session_options, :set_session_options_with_components
|
||||||
|
|
||||||
|
alias_method :flash_without_components, :flash
|
||||||
|
alias_method :flash, :flash_with_components
|
||||||
end
|
end
|
||||||
|
|
||||||
# If this controller was instantiated to process a component request,
|
# If this controller was instantiated to process a component request,
|
||||||
|
@ -110,6 +113,19 @@ module ActionController #:nodoc:
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def flash_with_components(refresh = false)
|
||||||
|
if @flash.nil? || refresh
|
||||||
|
@flash =
|
||||||
|
if @parent_controller
|
||||||
|
@parent_controller.flash
|
||||||
|
else
|
||||||
|
flash_without_components
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@flash
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def component_response(options, reuse_response)
|
def component_response(options, reuse_response)
|
||||||
klass = component_class(options)
|
klass = component_class(options)
|
||||||
|
|
|
@ -28,6 +28,9 @@ module ActionController #:nodoc:
|
||||||
base.send :include, InstanceMethods
|
base.send :include, InstanceMethods
|
||||||
|
|
||||||
base.class_eval do
|
base.class_eval do
|
||||||
|
alias_method :assign_shortcuts_without_flash, :assign_shortcuts
|
||||||
|
alias_method :assign_shortcuts, :assign_shortcuts_with_flash
|
||||||
|
|
||||||
alias_method :process_cleanup_without_flash, :process_cleanup
|
alias_method :process_cleanup_without_flash, :process_cleanup
|
||||||
alias_method :process_cleanup, :process_cleanup_with_flash
|
alias_method :process_cleanup, :process_cleanup_with_flash
|
||||||
end
|
end
|
||||||
|
@ -35,7 +38,7 @@ module ActionController #:nodoc:
|
||||||
|
|
||||||
|
|
||||||
class FlashNow #:nodoc:
|
class FlashNow #:nodoc:
|
||||||
def initialize flash
|
def initialize(flash)
|
||||||
@flash = flash
|
@flash = flash
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -134,6 +137,11 @@ module ActionController #:nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
|
def assign_shortcuts_with_flash(request, response) #:nodoc:
|
||||||
|
assign_shortcuts_without_flash(request, response)
|
||||||
|
flash(:refresh)
|
||||||
|
end
|
||||||
|
|
||||||
def process_cleanup_with_flash
|
def process_cleanup_with_flash
|
||||||
process_cleanup_without_flash
|
process_cleanup_without_flash
|
||||||
flash.sweep
|
flash.sweep
|
||||||
|
@ -143,19 +151,21 @@ module ActionController #:nodoc:
|
||||||
# Access the contents of the flash. Use <tt>flash["notice"]</tt> to read a notice you put there or
|
# Access the contents of the flash. Use <tt>flash["notice"]</tt> to read a notice you put there or
|
||||||
# <tt>flash["notice"] = "hello"</tt> to put a new one.
|
# <tt>flash["notice"] = "hello"</tt> to put a new one.
|
||||||
# Note that if sessions are disabled only flash.now will work.
|
# Note that if sessions are disabled only flash.now will work.
|
||||||
def flash #:doc:
|
def flash(refresh = false) #:doc:
|
||||||
@flash ||=
|
if @flash.nil? || refresh
|
||||||
if @parent_controller
|
@flash =
|
||||||
@parent_controller.flash
|
if @session.is_a?(Hash)
|
||||||
elsif @session.is_a?(Hash)
|
# @session is a Hash, if sessions are disabled
|
||||||
# @session is a Hash, if sessions are disabled
|
# we don't put the flash in the session in this case
|
||||||
# we don't put the flash in the session in this case
|
FlashHash.new
|
||||||
FlashHash.new
|
else
|
||||||
else
|
# otherwise, @session is a CGI::Session or a TestSession
|
||||||
# otherwise, @session is a CGI::Session or a TestSession
|
# so make sure it gets retrieved from/saved to session storage after request processing
|
||||||
# so make sure it gets retrieved from/saved to session storage after request processing
|
@session["flash"] ||= FlashHash.new
|
||||||
@session["flash"] ||= FlashHash.new
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@flash
|
||||||
end
|
end
|
||||||
|
|
||||||
# deprecated. use <tt>flash.keep</tt> instead
|
# deprecated. use <tt>flash.keep</tt> instead
|
||||||
|
|
Loading…
Reference in a new issue