跳至內容 跳至搜尋
方法
#
A
C
D
E
I
K
N
S
T
已包含模組

實體公開方法

[](k)

# File actionpack/lib/action_dispatch/middleware/flash.rb, line 169
def [](k)
  @flashes[k.to_s]
end

[]=(k, v)

# File actionpack/lib/action_dispatch/middleware/flash.rb, line 163
def []=(k, v)
  k = k.to_s
  @discard.delete k
  @flashes[k] = v
end

alert()

flash[:alert] 的便捷存取器。

# File actionpack/lib/action_dispatch/middleware/flash.rb, line 280
def alert
  self[:alert]
end

alert=(message)

flash[:alert]= 的便捷存取器。

# File actionpack/lib/action_dispatch/middleware/flash.rb, line 285
def alert=(message)
  self[:alert] = message
end

clear()

# File actionpack/lib/action_dispatch/middleware/flash.rb, line 204
def clear
  @discard.clear
  @flashes.clear
end

delete(key)

立即刪除單個 flash 項目。當您想在目前的動作中移除訊息時,請使用此方法。另請參閱 discard

# File actionpack/lib/action_dispatch/middleware/flash.rb, line 189
def delete(key)
  key = key.to_s
  @discard.delete key
  @flashes.delete key
  self
end

discard(k = nil)

標記整個 flash 或單個 flash 項目,以便在目前動作結束時捨棄

flash.discard              # discard the entire flash at the end of the current action
flash.discard(:warning)    # discard only the "warning" entry at the end of the current action

當您想在目前的動作中顯示訊息,但不想在下一個動作中顯示時,請使用此方法。另請參閱 delete

# File actionpack/lib/action_dispatch/middleware/flash.rb, line 264
def discard(k = nil)
  k = k.to_s if k
  @discard.merge Array(k || keys)
  k ? self[k] : self
end

each(&block)

# File actionpack/lib/action_dispatch/middleware/flash.rb, line 209
def each(&block)
  @flashes.each(&block)
end

empty?()

# File actionpack/lib/action_dispatch/middleware/flash.rb, line 200
def empty?
  @flashes.empty?
end

initialize_copy(other)

# File actionpack/lib/action_dispatch/middleware/flash.rb, line 155
def initialize_copy(other)
  if other.now_is_loaded?
    @now = other.now.dup
    @now.flash = self
  end
  super
end

keep(k = nil)

保留整個目前的 flash 或特定的 flash 項目,以供下一個動作使用

flash.keep            # keeps the entire flash
flash.keep(:notice)   # keeps only the "notice" entry, the rest of the flash is discarded
# File actionpack/lib/action_dispatch/middleware/flash.rb, line 250
def keep(k = nil)
  k = k.to_s if k
  @discard.subtract Array(k || keys)
  k ? self[k] : self
end

key?(name)

# File actionpack/lib/action_dispatch/middleware/flash.rb, line 183
def key?(name)
  @flashes.key? name.to_s
end

keys()

# File actionpack/lib/action_dispatch/middleware/flash.rb, line 179
def keys
  @flashes.keys
end

notice()

flash[:notice] 的便捷存取器。

# File actionpack/lib/action_dispatch/middleware/flash.rb, line 290
def notice
  self[:notice]
end

notice=(message)

flash[:notice]= 的便捷存取器。

# File actionpack/lib/action_dispatch/middleware/flash.rb, line 295
def notice=(message)
  self[:notice] = message
end

now()

設定一個 flash,該 flash 將無法在下一個動作中使用,僅在目前動作中可用。

flash.now[:message] = "Hello current action"

此方法允許您將 flash 用作應用程式中的中央訊息系統。當您需要將物件傳遞給下一個動作時,您可以使用標準 flash 指派 ([]=)。當您需要將物件傳遞給目前動作時,您可以使用 now,並且您的物件將在目前動作完成後消失。

透過 now 設定的項目,其存取方式與標準項目相同:flash['my-key']

此外,還帶來了兩個便捷的存取器

flash.now.alert = "Beware now!"
# Equivalent to flash.now[:alert] = "Beware now!"

flash.now.notice = "Good luck now!"
# Equivalent to flash.now[:notice] = "Good luck now!"
# File actionpack/lib/action_dispatch/middleware/flash.rb, line 241
def now
  @now ||= FlashNow.new(self)
end

to_hash()

# File actionpack/lib/action_dispatch/middleware/flash.rb, line 196
def to_hash
  @flashes.dup
end

實體保護方法

now_is_loaded?()

# File actionpack/lib/action_dispatch/middleware/flash.rb, line 300
def now_is_loaded?
  @now
end

實體私有方法

stringify_array(array)

# File actionpack/lib/action_dispatch/middleware/flash.rb, line 305
def stringify_array(array) # :doc:
  array.map do |item|
    item.kind_of?(Symbol) ? item.to_s : item
  end
end