方法
实例公共方法
add_flash_types(*types) 链接
创建新的 flash 类型。您可以传递任意数量的类型来创建除默认的 alert 和 notice 之外的其他 flash 类型,这些类型将在您的控制器和视图中可用。例如:
# 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 %>
此方法将为每个给定名称自动定义一个新方法,该方法将在您的视图中可用。
源代码: 显示 | 在 GitHub 上
# 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 private type helper_method(type) if respond_to?(:helper_method) self._flash_types += [type] end end