Module: ActionController::Flash::ClassMethods
Relationships & Source Files | |
Defined in: | actionpack/lib/action_controller/metal/flash.rb |
Instance Method Summary
-
#add_flash_types(*types)
Creates new flash types.
- #action_methods Internal use only
Instance Method Details
#action_methods
This method is for internal use only.
[ GitHub ]
# File 'actionpack/lib/action_controller/metal/flash.rb', line 47
def action_methods # :nodoc: @action_methods ||= super - _flash_types.map(&:to_s).to_set end
#add_flash_types(*types)
Creates new flash types. You can pass as many types as you want to create flash types other than the default alert
and notice
in your controllers and views. For instance:
# 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 %>
This method will automatically define a new method for each of the given names, and it will be available in your views.
# 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