略過本文 略過搜尋
方法
A

執行個體公用方法

add_flash_types(*types)

建立新的快閃類型。您可以傳遞任意數量作為類型參數,建立快閃類型作為控制器和檢視中預設的 alertnotice 以外的類型。例如

# in application_controller.rb
class ApplicationController < ActionController::Base
  add_flash_types :warning
end

# in your controller
redirect_to user_path(@user), warning: "Incomplete profile"

# in your view
<%= warning %>

此方法會自動為每個給定的名稱自動定義一個新方法,並會在您的檢視中提供。

# File actionpack/lib/action_controller/metal/flash.rb, line 34
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) if respond_to?(:helper_method)

    self._flash_types += [type]
  end
end