跳至内容 跳至搜索
方法
#
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)

立即删除单个闪存条目。当您想要在当前操作中删除消息时,使用此方法。另请参见 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.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.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.now[:message] = "Hello current action"

此方法使您能够在应用程序中使用闪存作为集中式消息传递系统。当您需要将对象传递给下一个操作时,使用标准闪存分配 ([]=)。当您需要将对象传递给当前操作时,使用 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