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