方法
实例公共方法
add_flash_types(*types) 链接
创建新的闪存类型。您可以传递任意数量的类型来创建除了默认的 alert
和 notice
之外的闪存类型,在控制器和视图中。例如
# 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 32 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