mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Lazy load flash access
This commit is contained in:
parent
9a733f6c64
commit
7c09050999
2 changed files with 14 additions and 10 deletions
|
@ -27,8 +27,8 @@ module ActionController #:nodoc:
|
||||||
def self.included(base)
|
def self.included(base)
|
||||||
base.class_eval do
|
base.class_eval do
|
||||||
include InstanceMethods
|
include InstanceMethods
|
||||||
alias_method_chain :assign_shortcuts, :flash
|
alias_method_chain :perform_action, :flash
|
||||||
alias_method_chain :reset_session, :flash
|
alias_method_chain :reset_session, :flash
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -135,22 +135,26 @@ module ActionController #:nodoc:
|
||||||
|
|
||||||
module InstanceMethods #:nodoc:
|
module InstanceMethods #:nodoc:
|
||||||
protected
|
protected
|
||||||
|
def perform_action_with_flash
|
||||||
|
perform_action_without_flash
|
||||||
|
remove_instance_variable(:@_flash) if defined? @_flash
|
||||||
|
end
|
||||||
|
|
||||||
def reset_session_with_flash
|
def reset_session_with_flash
|
||||||
reset_session_without_flash
|
reset_session_without_flash
|
||||||
remove_instance_variable(:@_flash)
|
remove_instance_variable(:@_flash) if defined? @_flash
|
||||||
end
|
end
|
||||||
|
|
||||||
# Access the contents of the flash. Use <tt>flash["notice"]</tt> to
|
# Access the contents of the flash. Use <tt>flash["notice"]</tt> to
|
||||||
# read a notice you put there or <tt>flash["notice"] = "hello"</tt>
|
# read a notice you put there or <tt>flash["notice"] = "hello"</tt>
|
||||||
# to put a new one.
|
# to put a new one.
|
||||||
def flash #:doc:
|
def flash #:doc:
|
||||||
@_flash ||= session["flash"] ||= FlashHash.new
|
unless defined? @_flash
|
||||||
end
|
@_flash = session["flash"] ||= FlashHash.new
|
||||||
|
@_flash.sweep
|
||||||
|
end
|
||||||
|
|
||||||
private
|
@_flash
|
||||||
def assign_shortcuts_with_flash(request, response) #:nodoc:
|
|
||||||
assign_shortcuts_without_flash(request, response)
|
|
||||||
flash.sweep if @_session
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -232,7 +232,7 @@ module ActionController #:nodoc:
|
||||||
|
|
||||||
# Do we have a flash?
|
# Do we have a flash?
|
||||||
def has_flash?
|
def has_flash?
|
||||||
!session['flash'].empty?
|
!flash.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Do we have a flash that has contents?
|
# Do we have a flash that has contents?
|
||||||
|
|
Loading…
Reference in a new issue