Add a preparation callback. Preparation callbacks are run before every request in development mode, and before the first request in production mode.
An optional identifier may be supplied for the callback. If provided, to_prepare may be called again with the same identifier to replace the existing callback. Passing an identifier is a suggested practice if the code adding a preparation block may be reloaded.
Source Code
# File dispatcher.rb, line 76 def to_prepare(identifier = nil, &block) unless identifier.nil? callback = preparation_callbacks.detect { |ident, _| ident == identifier } if callback # Already registered: update the existing callback callback[-1] = block return end end preparation_callbacks << [identifier, block] return end
<code/>and<pre/>for code samples.