diff options
author | kennyj <kennyj@gmail.com> | 2012-07-07 03:34:56 +0900 |
---|---|---|
committer | kennyj <kennyj@gmail.com> | 2012-07-07 17:07:57 +0900 |
commit | 238a4253bf229377b686bfcecc63dda2b59cff8f (patch) | |
tree | 5471959a9d68f6aca5a2147efc5a24e1d06df6b1 /actionpack/lib | |
parent | c55df9301c34ae9778c6a7ffadaeeb3247017cde (diff) | |
download | rails-238a4253bf229377b686bfcecc63dda2b59cff8f.tar.gz rails-238a4253bf229377b686bfcecc63dda2b59cff8f.tar.bz2 rails-238a4253bf229377b686bfcecc63dda2b59cff8f.zip |
Added support add_flash_types
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/metal/flash.rb | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/actionpack/lib/action_controller/metal/flash.rb b/actionpack/lib/action_controller/metal/flash.rb index bd768b634e..47e71371e3 100644 --- a/actionpack/lib/action_controller/metal/flash.rb +++ b/actionpack/lib/action_controller/metal/flash.rb @@ -3,19 +3,34 @@ module ActionController #:nodoc: extend ActiveSupport::Concern included do + class_attribute :_flash_types, :instance_methods => false + self._flash_types = [] + delegate :flash, :to => :request - delegate :alert, :notice, :to => "request.flash" - helper_method :alert, :notice + add_flash_types(:alert, :notice) end - protected - def redirect_to(options = {}, response_status_and_flash = {}) #:doc: - if alert = response_status_and_flash.delete(:alert) - flash[:alert] = alert + module ClassMethods + def add_flash_types(*types) + types.each do |type| + next if _flash_types.include?(type) + + define_method(type) do + request.flash[type] + end + helper_method type + + _flash_types << type end + end + end - if notice = response_status_and_flash.delete(:notice) - flash[:notice] = notice + protected + def redirect_to(options = {}, response_status_and_flash = {}) #:doc: + self.class._flash_types.each do |flash_type| + if type = response_status_and_flash.delete(flash_type) + flash[flash_type] = type + end end if other_flashes = response_status_and_flash.delete(:flash) |